hellow everyone . i have 2 following matricces .Say A =['dog' ;'cat' ; 'cow'] . B= [1;2;3] . now i want to get a matrix C such that C=['dog' 1;'cat' 2;'cow' 3]. please help me out.

 채택된 답변

Guillaume
Guillaume 2014년 9월 5일

0 개 추천

It's not possible. A is a matrix of char, B is a matrix of doubles. All elements of a matrix must be of the same type.
What you can do is put them into a cell array, but the syntax for accessing elements is different:
C = [num2cell(A, 2) num2cell(B)]
%access elements of C:
cat = C{2, 1};
three = C{3, 2};
If A and B were of the same type and size (A=[4;5;6], B=[1;2;3]), you could just concatenate them
C = [A B];

추가 답변 (1개)

Yawar Rehman
Yawar Rehman 2014년 9월 5일

0 개 추천

A = ['dog '; 'cat '; 'cow '];
B = [1 ; 2 ; 3]; B = num2str(B);
comb = [A B]

댓글 수: 1

pradeep kumar
pradeep kumar 2014년 9월 5일
Thank you Yawar Rehman .Your reply as very simple . I am just a beginner in MATLAB. I expect the similar coperation from you , if i face any futher difficulties. Thanks once again . have a good day !

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2014년 9월 5일

댓글:

2014년 9월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by