필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

how can I create a name like myfunc500?!

조회 수: 1 (최근 30일)
mim
mim 2013년 9월 17일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a lot of matrices with these names:
A200
A300
A400
...
and I want to do some algebra on each of them. I am looking for writing a loop to do all of them together, but how can I do it? I need to write a loop like:
for i =200:100:500
Ai(50,50) = mean (:,50)
end
but it is not possible in this way. Does anyone has a suggestion?
thanks
  댓글 수: 1
Jan
Jan 2013년 9월 17일
A very very frequently asked question. And the solution is always the same: Do not hide indices in the names of variables. Use indices as indices instead. See Walter's answer.

답변 (2개)

Walter Roberson
Walter Roberson 2013년 9월 17일

Image Analyst
Image Analyst 2013년 9월 18일
If you have just a handful of them (say, less than 7 or 8) then just deal with them one at a time or pass them into a function if you want to do the same things on all of them.
ProcessData(A100);
ProcessData(A200);
....
ProcessData(A800);
If you have more than that, I'd try to change the m-file that created them so it doesn't create them but creates regular indexed arrays, like a 3D array if you have 300 2D arrays to deal with,
for plane = 1 : 800
ProcessData(A(:,:,plane));
end
or (last resort) use a cell array.
for theCellIndex = 1 : 800 % Process 800 arrays inside cells.
ProcessData(A{theCellIndex});
end
See the FAQ for a discussion of cells.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by