フィルターのクリア

how can I check if there is a cell in a structure?

4 ビュー (過去 30 日間)
Gianmarco Manzo
Gianmarco Manzo 2020 年 1 月 28 日
コメント済み: Gianmarco Manzo 2020 年 1 月 29 日
Hello,
I have a structure that is dynamically filled through a for loop if certain conditions are met. It happens, however, that if the for loop reaches the end and the condition is not respected, I have a structure with a field that has one less element. How can I automatically check if this field has been completely filled?
for example in the code below it is verified that the cell 'struct.hi (1,2)' does not exist because the condition has not been respected. When I run under the control with 'isempty' and I get to the third cell I get this error: Index in position 2 exceeds array bounds (must not exceed 1).
x=[2,4,5];
for i=1:2
if expression
struct.hi(1,i)=x;
end
end
for j=1:2
if isempty(struct.hi(1,i)==0)
istructions
end
end

採用された回答

Sindar
Sindar 2020 年 1 月 29 日
Check the size of struct.hi. If the second dimension is size 1, then the struct.hi(1,2) doesn't exist
if size(struct.hi,2) == 1
Also, I wouldn't use struct as a variable name, since it is an important built-in
  1 件のコメント
Gianmarco Manzo
Gianmarco Manzo 2020 年 1 月 29 日
ok I try. Oh yes, it was only and example name. In reality my struct's name is FC. Thx.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by