array

1 次查看(过去 30 天)
AYAH
AYAH 2012-6-17
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

回答(2 个)

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

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2012-6-17
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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by