Filter löschen
Filter löschen

automatic creating of array

6 Ansichten (letzte 30 Tage)
john
john am 26 Okt. 2011
Hi,
I would like automatic create a matrix, or array. My program should work like this:
If I insert any number n, then it will create matrix, or array with elements i1;i2;i3;..in with size nx1.
For example: if n=2; then result is [i1;i2],
ans =
i1
i2
if n=4; then result is [i1;i2;i3;i4].
Please can you help me?
Thank you
  4 Kommentare
john
john am 26 Okt. 2011
Daniel,
{'i1','i2'} will by perfect. Do you know do this?
Matt Tearle,
I use usually command sym for create i1, i2.... in M-file. For me 1,2,3 and i1,i2 are the same, mean the same.
But Matlab help is written: sym Define symbolic objects
So I don't know what is 1,2,3,4, and i1,i2...
Jan
Jan am 27 Okt. 2011
@vansac: This is a public forum. Please post your questions here and not per email. Please take the time to read my profile.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 26 Okt. 2011
a=(1:n)'
or
a=cellstr(strcat('i',num2str((1:n)')))
  3 Kommentare
Fangjun Jiang
Fangjun Jiang am 26 Okt. 2011
Good point. Updated!
john
john am 26 Okt. 2011
Thank you so much Fangjun Jiang, good job :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by