Delete columns in a structure array

2 ビュー (過去 30 日間)
SS
SS 2021 年 6 月 28 日
編集済み: SS 2021 年 6 月 29 日
Hello.
I have a structure array Data (1 x 500,000) with 10 fields f1, f2,.......f10. I want to delete all the columns i.e., Data(i) whose f10 > 100.
For example, if the below is the input:
Data(1).f1=[10,70,30 40,50,60], Data(1).f2=[100,20,50,60,70,140],......Data(1).f10=[-10,20,-50,42,-70,140] ;
Data(2).f1=[16,98,74,47,99], Data(2).f2=[101,54,69,20,11],.......Data(2).f10=[17,-54,69,-20,37];
Data(3).f1=...... , Data(3).f2=.....,........ Data(3).f10=...........;
Data(4).f1=.... , Data(4).f2=....., ....... Data(4).f10=............;
.
.
Data(i).f1=...., Data(i).f2=.... and Data(i).f10=............;
In Data(1).f10 there is an entry 140 which is greater than 100 so, I want to delete the whole column Data(1).
I have tried below option but, it does not help.
for i=1:length(Data)
i
if (Data(i).f10 > 100)
Data(i)=[]
end
end
save('Data.mat')

採用された回答

Stephen23
Stephen23 2021 年 6 月 28 日
Assuming that the data in f10 is scalar numeric (you did not tell us this important information):
idx = [Data.f10]>10;
Data = Data(~idx)
save('Data.mat','Data')
  3 件のコメント
Stephen23
Stephen23 2021 年 6 月 29 日
"This is a bit confusing."
It is not very confusing: in your original question you omitted to give very important information, such as the sizes of the structure fields. Now that you have edited your question, we can make some progress:
fun = @(s) any(s.f10(:)>10);
idx = arrayfun(fun,Data);
Data = Data(~idx);
SS
SS 2021 年 6 月 29 日
編集済み: SS 2021 年 6 月 29 日
Thanks a lot.

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

その他の回答 (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