フィルターのクリア

Structure of array: deletion of null elements

1 回表示 (過去 30 日間)
Andrea Giordano
Andrea Giordano 2022 年 10 月 10 日
編集済み: Jan 2022 年 10 月 10 日
In a for loop, I am reading data from a .csv file, and copying them into a structure made of several arrays, fixed number of elements (276). Depending on the structure array called f_avg, I would like to keep or delete the whole structure element. For instance, if f_avg(k, 1)== 0, I would like to delete the k_th element of each array belonging to that structure. To do so, I tried the following (see below), getting the error "The logical indices contain a true value outside of the array
bounds.
Error in data_analysis_multiple_files (line 65)
exp_value = exp_value(exp_value.f_avg(:, 1)~=0)". Thank you in advance for your help.
exp_value = exp_value(exp_value.f_avg(:, 1)~=0);
  2 件のコメント
Jan
Jan 2022 年 10 月 10 日
What do you call "the whole structure element"?
exp_value is the struct, correct? Which dimensions does it have? Which size has exp_value.f_avg? The error message means, that exp_value.f_avg(:, 1) has more elements than exp_value.
Andrea Giordano
Andrea Giordano 2022 年 10 月 10 日
Sorry, my bad. Yes, exp_value is the structure i mention (1 x 1 structure), 7 fields:
f_avg (276 x 3) double
f_std (276 x 3) double
t_avg (276 x 3) double
t_std (276 x 3) double
aoa (276 x 1) double
vel (276 x 1) double
inflation (276 x 1) double

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

採用された回答

Jan
Jan 2022 年 10 月 10 日
編集済み: Jan 2022 年 10 月 10 日
S = exp_value; % Just for readability
remove = (S.f_avg(:, 1) == 0);
fields = setdiff(fieldnames(S), {'f_avg'}); % All fields but f_avg
for k = 1:numel(fields)
S.(fields{k})(remove, :) = [];
end
Slightly shorter, but with strange loop over a cell string:
S = exp_value; % Just for readability
remove = (S.f_avg(:, 1) == 0);
fields = setdiff(fieldnames(S), {'f_avg'}); % All fields but f_avg
for F = fields
S.(F)(remove, :) = [];
end

その他の回答 (1 件)

Chunru
Chunru 2022 年 10 月 10 日
exp_value(exp_value.f_avg(:, 1)==0) = [];
  1 件のコメント
Andrea Giordano
Andrea Giordano 2022 年 10 月 10 日
Matrix index is out of range for deletion.
Error in data_analysis_multiple_files (line 66)
exp_value(exp_value.f_avg(:, 1)==0) = [];

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

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by