필터 지우기
필터 지우기

How to call an array by its indice

조회 수: 1 (최근 30일)
regaieg rym
regaieg rym 2019년 2월 17일
답변: Geoff Hayes 2019년 2월 17일
Hello,
I have some number of arrays with diffrent dimensions
For example :
d1=[[1,2,3];[11,22,33];[111,222,333]]
d2=[[4,5,6];[44,55,66]]
d3=[[7,8,9]]
SO after i would like to call the above arrays by their indices:
for u=1:3
s=d{u )
end
How could I do that.
thanks

채택된 답변

Geoff Hayes
Geoff Hayes 2019년 2월 17일
regaeig - don't try to call the above arrays by their indices. This can lead to errors, confusion, etc. and has been discussed in great detail on this forum (see Stephen's post at Why Variables Should Not Be Named Dynamically (eval)). Instead, just save your data to a cell array
myData = cell(3,1);
myData{1} = [[1,2,3];[11,22,33];[111,222,333]];
myData{2} = [[4,5,6];[44,55,66]];
myData{3} = [[7,8,9]];
and then access the data as
for u =1:3
s = myData{u};
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by