Quickly access a group of arrays using a loop

Hi,
I have a set of arrays labeled as "A1", "A2", "A3"..."An" What I would like to do is write a loop that allows me to access each without having to type the array names out individually. For instance if I wanted to access the first entry of each array:
for i=1:n A "i" (1) end
I've been messing with num2str and eval but I can't seem to get something that works. Any pointers would be appreciated.
Cheers, David

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 10월 13일

0 개 추천

Using num2str() and eval() should be able to do it. See this post for details. But it is highly recommended not to name variable as A1, A2, A3,... as you now see the problem.

댓글 수: 1

David
David 2011년 10월 13일
Thanks Fangjun.
Out of interest I got it to work with:
for i=1:n
A{i}=eval[('A' num2str(i))];
A{i}(1)
end
Cheers,
David

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2011년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by