Writing characters to empty matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I am writing a loop to construct individual row names for n-rows. The row ids will be characters and not numbers. Additionally, I need to make a one dimensional (row) matrix to write the variable name to the respective row through each loop. If I was writing numbers to the variable, e.g. vardata = zeros(rownum),then it would be no problem. But I cannot figure out how to create an empty matrix to write characters to an empty matrix. Additionally, will it matter if the size of the row id changes? For example, the size of the row id for the first 10 iterations will be something like abc_x_1 then for the next 90 iterations abc_x_12, and for the last two iterations abc_x_123.
Thanks,
Eric
댓글 수: 0
채택된 답변
Matt Fig
2012년 9월 29일
편집: Matt Fig
2012년 9월 29일
You may want to use cell arrays.
for ii = 30:-1:1
T{ii} = sprintf('abc_x_%i',ii);
end
Now look:
T{25}
Then if you really need a character array, let MATLAB take care of the spacing problems for you:
char(T)
댓글 수: 7
Walter Roberson
2012년 9월 30일
There is no way to write both characters and numbers to a numeric or character array. Only cell arrays can hold both numbers and characters.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!