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