필터 지우기
필터 지우기

Concatenate

조회 수: 7 (최근 30일)
Alexandros
Alexandros 2011년 12월 13일
Dear matlabians
I have a cell variable z = (hello1 hello2 hello3) another cell variable y = (bye1 bye2 bye3) and a double x = (1;2;3 , 4;5;6 , 7;8;9)
how i can I concatenate them in a 5x3 vector
v = (hello1;bye1;1;2;3 , hello2;bye2;4;5;6 , hello3;bye3;7;8;9)
thank you
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2011년 12월 13일
What you have shown for v is a 3x5.

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

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 12월 13일
This makes the 5x3 that you requested.
c1 = {'hello' 'world' 'Happy Tuesday'};
c2 = {'Need' 'coffee' 'now'};
m1 = magic(3);
C = vertcat(c1,c2,num2cell(m1));
To make a 3x5 use;
C = horzcat(c1',c2',num2cell(m1));

추가 답변 (2개)

Laura Proctor
Laura Proctor 2011년 12월 13일
z = {'hello1','hello2','hello3'};
y = {'bye1','bye2','bye3'};
x = reshape(1:9,3,3);
v = [ z ; y ; num2cell(x) ]

the cyclist
the cyclist 2011년 12월 13일
Here is one way. I have tried to stick somewhat close to the non-MATLAB notation that you used in your question, but still have working code:
z = {'hello1','hello2','hello3'};
y = {'bye1','bye2','bye3'};
x = [1,2,3;4,5,6;7,8,9];
v = [z',y',num2cell(x)]
The key concept that you need is the use of num2cell() to convert the numerical matrix into a cell array, so that it can be mixed with the strings.
  댓글 수: 1
Alexandros
Alexandros 2011년 12월 13일
Thank you so much people for all this answers it work perfectly. I have been programming first time with matlab 2 months now and I have made to fuctions and 1000 lines of code. But i still don't get all the variables that you could have in matlab
Do you have any good tutorial that I could read?
thanks

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

카테고리

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