Azzera filtri
Azzera filtri

array

1 visualizzazione (ultimi 30 giorni)
AYAH
AYAH il 17 Giu 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

Risposte (2)

Andrei Bobrov
Andrei Bobrov il 17 Giu 2012
Y = eval(['[',sprintf('Y%-d,',1:n),']'])
  1 Commento
Walter Roberson
Walter Roberson il 17 Giu 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.

Accedi per commentare.


Walter Roberson
Walter Roberson il 17 Giu 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

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by