how to create a matrix in matlab

조회 수: 16 (최근 30일)
marwa hajji
marwa hajji 2022년 2월 1일
댓글: Image Analyst 2022년 2월 2일
I have A=[1 3; 2 4]; and B=[5 6; 7 8];
I would like to create this two matrix line by line in C :
C=[1 3;5 6; 2 4; 7 8];
  댓글 수: 5
marwa hajji
marwa hajji 2022년 2월 2일
thank you very much , yes exactly!!!!
Image Analyst
Image Analyst 2022년 2월 2일
@marwa hajji did you see my Answer below (scroll down to the official Answers section, not up here in the comments section which is supposed to be used to ask the original poster for clarification)?

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

답변 (2개)

Benjamin Thompson
Benjamin Thompson 2022년 2월 1일
A couple different ways:
>> A = [1 3; 2 4]
A =
1 3
2 4
>> B = [5 6; 7 8]
B =
5 6
7 8
>> C = A
C =
1 3
2 4
>> C = [C; B]
C =
1 3
2 4
5 6
7 8
>> C = [A; B]
C =
1 3
2 4
5 6
7 8
  댓글 수: 1
Image Analyst
Image Analyst 2022년 2월 1일
This
C =
1 3
2 4
5 6
7 8
is not what he wanted. He said he wants
C=[1 3;5 6; 2 4; 7 8]
C = 4×2
1 3 5 6 2 4 7 8

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


Image Analyst
Image Analyst 2022년 2월 1일
Try this:
A=[1 3; 2 4]
A = 2×2
1 3 2 4
B=[5 6; 7 8]
B = 2×2
5 6 7 8
% What is desired:
C = [1 3;5 6; 2 4; 7 8]
C = 4×2
1 3 5 6 2 4 7 8
% My code
C2 = [A(1,:); B(1, :); A(2,:); B(2,:)]
C2 = 4×2
1 3 5 6 2 4 7 8
If you need it generalized to interleave a different number of rows than 2, or if A and B might have different numbers of rows, then it would be more complicated.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by