access multidimensional array per row

14 ビュー (過去 30 日間)
Joyce Shin
Joyce Shin 2017 年 2 月 9 日
コメント済み: Joyce Shin 2017 年 2 月 10 日
Hi,
I have 10x1 cell named Results in which includes 672x7 cell in each cell. For 672x7 cell, I want to access row by row. However, it throws an error saying "Index exceeds matrix dimensions." Can you see which line is a problem?
for i1=1:size(Results,1) % 10*1 cell
for i2=1:size(Results{i1,1}) % 672*7 cell
for i3=1:size(tc,2) % 7 methods
min(Results{i1,i2}(i3,:))
end
end
end

回答 (1 件)

James Tursa
James Tursa 2017 年 2 月 9 日
編集済み: James Tursa 2017 年 2 月 9 日
i2 ranges from 1 to 1st dimension of Results{i1}, which is 672. You can't then turn around and use this as the 2nd index in Results. I.e., Results{i1,i2} can't use i2 in that 2nd index since that dimension only goes up to 1. So you need to rethink and redo that Results{i1,i2}(i3,:) reference. It's going to have to look like Results{i1}{i2,something}etc.
Also, your for loops have size(something) as an upper limit, but size returns a vector. Do you really want to use numel(something) or size(something,1) instead?
  2 件のコメント
Joyce Shin
Joyce Shin 2017 年 2 月 10 日
Hi, Thanks for the comment. If I modify my code this way, it works. I removed i3, since I already know the range.
Results{i1}(i2,1:7)
Joyce Shin
Joyce Shin 2017 年 2 月 10 日
And can you suggest any other way other than size() to get array size?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by