having trouble with changing Matrix name

8 Ansichten (letzte 30 Tage)
Razieh
Razieh am 23 Apr. 2015
Bearbeitet: Stephen23 am 19 Jun. 2019
I want to name my outputs A_10_1, A-10_2,..., A_10_n; A_20_1, A_20_2,...,A_m_n; Where output A_m_n was generated with variable m and it is nth replication result.
Please help me to write code thanks
  1 Kommentar
Stephen23
Stephen23 am 23 Apr. 2015
Bearbeitet: Stephen23 am 19 Jun. 2019
Your terminology is not clear because you are mixing the terms file and variable. Are you talking about a file of data that is saved on a hard-drive, or a variable (e.g. a matrix) that is inside MATLAB's workspace?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Thorsten
Thorsten am 25 Apr. 2015
You can store matrices of different sizes in a cell array:
for m=1:Nm
for n=1:Nn
A{m,n} = myfunction(m,n);
end
end

Weitere Antworten (2)

Image Analyst
Image Analyst am 23 Apr. 2015
In short, to create a filename from two integers, do this
for m = 1 : whateverM
for n = 1 : whateverN
filename = sprintf('A_%d_%d.dat', m, n);
end
end
  4 Kommentare
Image Analyst
Image Analyst am 24 Apr. 2015
As Guillaume, Stephen, and now me (now that I know you want to create matrices and not filenames like you said in the subject line) all say, this is a bad idea and we recommend you read the FAQ to learn why. It's better if you just use functions to process the same named variable, within a loop to handle the 16 different cases where the array has different values, OR use a larger array so that all of your 16 arrays can be in the same single array, and you just get to them by changing the index.
Razieh
Razieh am 25 Apr. 2015
ok. thanks Image Analyst for the suggestion. I try to learn that

Melden Sie sich an, um zu kommentieren.


Stephen23
Stephen23 am 23 Apr. 2015
Bearbeitet: Stephen23 am 19 Jun. 2019
  2 Kommentare
Jan
Jan am 25 Apr. 2015
@Razieh: Please follow the links Stephen has posted. The topic of numbered names of variables has been discussed thousands of times before and this is a severely bad method of beginners. The solution is easy: NEVER hide indices in the names of variables, but use arrays instead.
Razieh
Razieh am 26 Apr. 2015
Thanks Jan Simon

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by