フィルターのクリア

Is it possible to use 'numel' in nested struct?

4 ビュー (過去 30 日間)
pamela sulis
pamela sulis 2016 年 3 月 9 日
コメント済み: Guillaume 2016 年 3 月 9 日
Hi! I use numel in a nested struct:
for i=1:9
for j=1:size(E(1,i).bcd,2)
for jj=1:numel(E(1,i).bcd{1,j}.b)
if(isempty(E(1,i).bcd{1,j}.b{jj}))
E(1,i).bcd{1,j}.b{jj}=''
end
end
end
end
but it gives this error
'Attempt to reference field of non-structure array.'
Is it possible that the error is in the use of numel? thanks
  1 件のコメント
KSSV
KSSV 2016 年 3 月 9 日
what is E?

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

採用された回答

Guillaume
Guillaume 2016 年 3 月 9 日
編集済み: Guillaume 2016 年 3 月 9 日
No, the error has nothing to do with numel. As the error says, you're attempting to access a field (b maybe) of something that is not a structure.
Assuming that E is really a structure. One of the cell array in the bcd fields does not contain a structure.
To check
for eidx = 1:numel(E)
for bcdidx = 1:numel(E(eidx).bcd)
if ~isstruct(E(eidx).bcd{bcdidx})
warning('E(%d).bcd{%d} is not a structure', eidx, bcdidx);
end
end
end
  2 件のコメント
pamela sulis
pamela sulis 2016 年 3 月 9 日
I try your code and I have an other error: 'Scalar index required for this type of multi-level indexing'. Thanks for your suggestion: surely there is an error in the dimensions of the struct or in the definition of the struct.
Guillaume
Guillaume 2016 年 3 月 9 日
I did make a typo in my code (used idx instead of eidx, most likely you already had a idx variable in your workspac). I've fixed it now and the code should run without error.
The problem is most likely that one of your cell array bcd is empty.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by