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

Stephen23
Stephen23 2015년 4월 23일
편집: Stephen23 2019년 6월 19일
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?

댓글을 달려면 로그인하십시오.

 채택된 답변

Thorsten
Thorsten 2015년 4월 25일

2 개 추천

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

추가 답변 (2개)

Image Analyst
Image Analyst 2015년 4월 23일

2 개 추천

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
Razieh 2015년 4월 23일
My file 'call it Z, for example' is a matrix that I want to save it with its values with this new name. However, when I use the above code the matrix is deleted and replaced with characters that are stated in sprintf.
How I keep the matrix but only change its name? by the way m and n are supplied by function call and represent input [output]=function F(m,n)
Guillaume
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
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
Razieh 2015년 4월 25일
ok. thanks Image Analyst for the suggestion. I try to learn that

댓글을 달려면 로그인하십시오.

Stephen23
Stephen23 2015년 4월 23일
편집: Stephen23 2019년 6월 19일

2 개 추천

댓글 수: 2

Jan
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
Razieh 2015년 4월 26일
Thanks Jan Simon

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2015년 4월 23일

편집:

2019년 6월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by