How to check if a element of a struct is empty?
90 ビュー (過去 30 日間)
古いコメントを表示
Dear All,
I defined a struct and initialize it in the following way.
Res_All_Meas = struct([]);
[Res_All_Meas(1000).ind] = 0;
[Res_All_Meas(1000).res] = 0;
[Res_All_Meas(1000).xline] = 0;
[Res_All_Meas(1000).colnum] = 0;
Now in an iteration, I want to check if Res_All_Meas(i) is empty or not. If it is empty, I will assign some valeus to it.
Thanks a lot.
Benson
3 件のコメント
Stephen23
2020 年 10 月 15 日
"I want to check if the field contents are empty."
See my answer.
"The field contents for Res_All_Meas(i) are zero before Res_all_Meas(i) is assigned a value."
Not in your example. What you showed has all fields of every structure element Res_All_Meas(1:999) containing empty numeric arrays, and the last element Res_All_Meas(1000) for which each field contains 0.
回答 (2 件)
Ameer Hamza
2020 年 10 月 14 日
2 件のコメント
Ameer Hamza
2020 年 10 月 15 日
You need to apply isempty on a particular field of a struct. Something like this
tf = ismpty(Res_All_Meas(1).ind)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!