Concatenate matrix with for loop

조회 수: 10 (최근 30일)
Catherine
Catherine 2018년 2월 21일
댓글: Star Strider 2018년 2월 21일
Hi guys,
I got 3 matrices that I want to concatenate into one. Each matrix is 4x200. What I want to do is to create a matrix that is like matrix c:
a =
8 1 6 5
3 5 7 6
4 9 2 7
b =
5 4 1 3
7 3 2 8
8 9 6 6
c = [a(:,1) b(:,1);a(:,2) b(:,2);a(:,3) b(:,3);a(:,4) b(:,4)]
c =
8 5
3 7
4 8
1 4
5 3
9 9
6 1
7 2
2 6
5 3
6 8
7 6
I want to use a for loop but I couldn't get it to work. Your help will be appreciated. Thank you!
  댓글 수: 3
per isakson
per isakson 2018년 2월 21일
Why for-loop?
Catherine
Catherine 2018년 2월 21일
I just thought it's the easiest way. If there is other ways, I am happy to try out as well. Thanks.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2018년 2월 21일
Try this:
c = [a(:) b(:)];
  댓글 수: 4
Catherine
Catherine 2018년 2월 21일
Great! that works well! Thank you
Star Strider
Star Strider 2018년 2월 21일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by