フィルターのクリア

indexing error: ()-indexing must appear last in an index expression

36 ビュー (過去 30 日間)
Sam
Sam 2013 年 5 月 10 日
コメント済み: Walter Roberson 2016 年 12 月 21 日
Do you know what is wrong with my indexing below? Thanks.
vars = {'Cs' 'beta' 'As' 'TCI' 'TWI' 'hs'}
tmp = cell(size(dem)) % create 20x1 supercell
out = tmp;
tmp2 = size(vars) % create 6x1 subarrays
out2 = zeros(tmp2);
for i=1:numel(dem)
for j=1:numel(vars)
*out{i} = out2(:,:,j)(Cs{i}, beta{i}, As{i}, TCI{i}, TWI{i}, hs{i});*
end
end
Error: ()-indexing must appear last in an index expression.

採用された回答

the cyclist
the cyclist 2013 年 5 月 10 日
編集済み: the cyclist 2013 年 5 月 10 日
In MATLAB you cannot index into an array that you've already indexed into, so you cannot do this
out{i} = out2(:,:,j)(Cs{i}, beta{i}, As{i}, TCI{i}, TWI{i}, hs{i})
But assuming the rest of your code is OK (which I could not check), then you could define a temp variable
out2_tmp = out2(:,:,j);
out{i} = out2_tmp(Cs{i}, beta{i}, As{i}, TCI{i}, TWI{i}, hs{i})
  2 件のコメント
Sam
Sam 2013 年 5 月 10 日
Thanks, Cyclist. That made progress yet led to a dreaded error I've hit numerous times but don't fully understand. This is my first attempt at a nested for loop. Can you offer more help? There is no other add'l code, although FYI each 'vars' is a 20x1 cell of n x m arrays.
vars = {'Cs' 'beta' 'As' 'TCI' 'TWI' 'hs'}
tmp = cell(size(dem))
out = tmp;
tmp2 = size(vars)
out2 = zeros(tmp2);
for i=1:numel(dem)
for j=1:numel(vars)
out2_tmp = out2(:,:,j);
out{i} = out2_tmp(Cs{i}, beta{i}, As{i}, TCI{i}, TWI{i}, hs{i});
end
end
Subscript indices must either be real positive integers or logicals.
the cyclist
the cyclist 2013 年 5 月 10 日
I can't really help debug your code, because it is not self-contained. However, I can give insight into that error.
x = [2 7 6 3];
idx_valid_integers = [1 3 4 2];
idx_valid_logical = [true true false true];
idx_invalid = [-1 0];
% Valid indexing
y = x(idx_valid_integers);
% Also valid indexing [using logical indexing]
y = x(idx_valid_logical);
% Not valid indexing (index is neither positive integer nor logical)
y = x(idx_invalid); % This will give you that same error.
The first two ways of indexing work, because I am either telling MATLAB a particular element (by its position) or by applying a logical "mask" to the entire vector.
But the third way does not work. What is the "-1" or "zeroth" element of a vector. It makes no sense.
Somehow, that is what you are doing in your code.

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

その他の回答 (1 件)

Bhargavkrishna Kondreddy
Bhargavkrishna Kondreddy 2016 年 10 月 26 日
% Importing all the 300 files
files = dir( 'imageset1_*.txt'); for i=1:numel(files) A{i} = dlmread( files(i).piv, '\t', 3 , 0 ); end
% Summation of X-components of the 300 files
Xsum ='A('1)(:,3); for k = 2:299 Xsum=Xsum+A(k)(:,3); end () indexing must appear last in an index expression at
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 12 月 21 日
MATLAB does not have implicit multiplication. You need to add * as appropriate.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by