필터 지우기
필터 지우기

Creating an array of string variables

조회 수: 2 (최근 30일)
Luke
Luke 2011년 8월 16일
Hello,
I am trying to create an array that holds a bunch of strings. My idea was to be able to index into the array in a for loop and access the string that is stored in that particular index. I am trying to do this but I keep getting a "Subscripted assiment dimension mismatch" error and I know what I want MATLAB to do, I just do not knw the syntax well enough to make it work. Here is a sample code of what I am trying...
name = 'DevilsWash_Multi_Sage_004_'; s_name = ['surface_' name ]; p = ones(9,30); for n = 1:length(p(:,1)) p(n)=[s_name int2str(n)]; end
As you can see, I am adding a number to each string to each is unique but I do not want to have each string be a variable in my workspace, I need them to be contained in an array. Any suggestions?
ps, I do not know how to enter code in MATLAB forums yet, sorry for any inconvenience there.
Thank you for your time and effort, Luke
  댓글 수: 1
Rick Rosson
Rick Rosson 2011년 8월 16일
To enter code, simply indent each line of code with two or three blank space characters. For regular non-code prose, you should NOT indent at all.

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

채택된 답변

Rick Rosson
Rick Rosson 2011년 8월 16일
Please try creating a "cell array" of strings:
myList = { 'Red' ; 'Orange' ; 'Yellow' ; 'Green' ; 'Blue' } ;
for k = 1:5
disp(myList{k});
end
Notice that cell arrays use curly braces instead of standard parentheses.
HTH.
Rick
  댓글 수: 1
Luke
Luke 2011년 8월 16일
yep, the cell works. Thanks!!!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by