having trouble with changing Matrix name
古いコメントを表示
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 件のコメント
採用された回答
その他の回答 (2 件)
Image Analyst
2015 年 4 月 23 日
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 件のコメント
Razieh
2015 年 4 月 23 日
Guillaume
2015 年 4 月 23 日
Files and matrices are two completely different things. It helps if you use the proper terminology.
DO NOT create matrices with dynamic names such as A_10_1. Instead use a single cell array or if all these matrices are the same size a higher dimension matrix.
Image Analyst
2015 年 4 月 24 日
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
2015 年 4 月 25 日
2 件のコメント
Jan
2015 年 4 月 25 日
@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
2015 年 4 月 26 日
カテゴリ
ヘルプ センター および File Exchange で Function Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!