フィルターのクリア

Writing IF STATEMENT that omits empty fields in different arrays of a structure

2 ビュー (過去 30 日間)
Ayobami Meadows
Ayobami Meadows 2023 年 1 月 25 日
コメント済み: Ayobami Meadows 2023 年 1 月 29 日
I need writing an if statement that would exclude empty fields in a structured array (pictured attached). I am to make use of non-empty fields of M.id, M.xd and M.yd. I came up with this but not working:
for i=1:1:n % n is 100
if ~isempty M(i) % this is where my problem lies
for z=1:t % t is 5
min_dis_local=inf;
distanceL=sqrt( (S(i).xd-(M(z).xd) )^2
end
end
end
I got this error instead:
Error using isempty
Not enough input arguments.
  1 件のコメント
Ayobami Meadows
Ayobami Meadows 2023 年 1 月 29 日
Please can anyone help with a solution to this stated problem?

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

回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2023 年 1 月 25 日
編集済み: Dyuman Joshi 2023 年 1 月 25 日
You need to use () with isempty, otherwise it would assume the input to be a string array
y = [];
isempty(y)
ans = logical
1
isempty y
ans = logical
0
%even though x is not defined, it returns 0 when checked with isempty
isempty x
ans = logical
0
When you add ~ operator before isempty without (), it will through you an error, which is what you encountered
~isempty y
  5 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 1 月 29 日
What is the full error you get when you run this code?
Ayobami Meadows
Ayobami Meadows 2023 年 1 月 29 日
Index exceeds the number of array elements (127)
Error in Demo_code (line 54) if ~isempty(M(i))

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

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by