array

1 view (last 30 days)
AYAH
AYAH on 17 Jun 2012
hello everybody
I would like to generate array Y=[Y1 Y2 Y3 Y4... Yn ] where n is unknown integer number and every "Y" is a column?
any help in this regard will be appreciated

Answers (2)

Andrei Bobrov
Andrei Bobrov on 17 Jun 2012
Y = eval(['[',sprintf('Y%-d,',1:n),']'])
  1 Comment
Walter Roberson
Walter Roberson on 17 Jun 2012
Bleh.
And besides, "n is unknown integer number", whereas your code would require it to be a known integer number at the time of execution.

Sign in to comment.


Walter Roberson
Walter Roberson on 17 Jun 2012
You might be able to do this in MATLAB if you designed your own Class (Object Oriented Programming.) But you'd have a lot of difficulty working out the details because even for simple operations like assignment, MATLAB wants to be able to find out the number of elements in the variable which is something you cannot answer when n is an unknown integer.
It is tempting to suggest that you create your array of unknown width in the Symbolic Toolbox, using MuPAD operations. The problem with that is that nearly all the MuPAD array-like datatypes work with arrays of known size. I think I saw one legacy table datatype that did not require fixed array bounds in MuPAD, but I am not certain.
If you happen to have the old Maple-based symbolic toolbox, then the old "array" (lower-case "A") and "table" (not "rtable") Maple data structures can handle symbolic bounds. But if you aren't careful, you will run into contradictions...
Matters would be a lot easier if the number of columns was variable rather than unknown. If it were merely variable, then see http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

Tags

Community Treasure Hunt

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

Start Hunting!