Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Errors in using string and vector together

조회 수: 2 (최근 30일)
Amit Kumar
Amit Kumar 2014년 10월 1일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi I want to display string and vector of floating point numbers together, but matlab flags error - 'dimensions of matrices are not consistent'.
Here is code:
str = {'A ';'B ','C '};
arr=[1;2;3];
disp([str,arr]);
I want to display like this
A 1
B 2
C 3
Is there any alternative way? I am also interested to know how to create vector of string like
A
B
C
Any ideas? Thanks a lot!

답변 (1개)

dpb
dpb 2014년 10월 1일
편집: dpb 2014년 10월 1일
>> disp([char(str) num2str(arr,' %d')])
A 1
B 2
C 3
>>
disp only takes a single argument and have to dereference the cell array and combine into character string array. To be able to concatenate to the numeric array, have to convert them to string as well.
Looping and fprintf is often just as simple to handle each row at a time.
For the latter ?, Matlab doesn't care whether the inputs to colon are characters...
>> ['A':'C'].'
ans =
A
B
C
>>

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by