Filter löschen
Filter löschen

Creating an array of string variables

2 Ansichten (letzte 30 Tage)
Luke
Luke am 16 Aug. 2011
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 Kommentar
Rick Rosson
Rick Rosson am 16 Aug. 2011
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rick Rosson
Rick Rosson am 16 Aug. 2011
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by