Drop column of values using if function

22 ビュー (過去 30 日間)
Mahshad Rabiee
Mahshad Rabiee 2021 年 4 月 22 日
編集済み: Scott MacKenzie 2021 年 4 月 22 日
I'm trying add some lines of code which drop columns that don't meet the condition. My values are 1500x28 matrix. Example:
if condition met
drop specific coloumn that meets condition
I know using A(:,3)=[] would drop column 3 but how do I not specify column number.
Thanks!
  2 件のコメント
Scott MacKenzie
Scott MacKenzie 2021 年 4 月 22 日
You can specify the column number as a variable. But, you'll need to set that variable to 3, perhaps through an if-else arrangement that includes the condition you allude to. More details would be helpful.
Mahshad Rabiee
Mahshad Rabiee 2021 年 4 月 22 日
Here is my code currently, i basically just want to ignore any columns in my plot where the percentage difference is less than 50%.
for i=1:length(mod_dirs)
%% ----------------------------------------------------MA data
% read the MomentArm (MA) data
MA_filename = [ base_dir mod_dirs{i} '\MA_MTL\' 'right_hip_muscle_flexion_MA.sto'];
MA = read_motionFile(MA_filename);
time = MA.data(:,2);
ma_flexion = MA.data(:,3:30);
ma_flexion_cm=ma_flexion*100;
mini_ma_flexion=min(ma_flexion_cm);
maxi_ma_flexion=max(ma_flexion_cm);
if (maxi_ma_flexion-mini_ma_flexion)<=(0.5*mini_ma_flexion);
ma_flexion_cm(:,:)=[];
continue;
end
[cycle_time,TN_ma_flexion]=normalise_data_points(time,ma_flexion_cm,t_cycle_start,t_cycle_end);
% create a plot of the MA of a selected muscle around the flex/ext axis
figure()
plot(cycle_time, TN_ma_flexion)

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

回答 (1 件)

Scott MacKenzie
Scott MacKenzie 2021 年 4 月 22 日
編集済み: Scott MacKenzie 2021 年 4 月 22 日
Set up a for-loop for your code, something like this.
time = MA.data(:,2);
for i=3:30
ma_flexion = MA.data(:,i);
ma_flexion_cm=ma_flexion*100;
mini_ma_flexion=min(ma_flexion_cm);
maxi_ma_flexion=max(ma_flexion_cm);
if (maxi_ma_flexion-mini_ma_flexion)<=(0.5*mini_ma_flexion)
ma_flexion_cm(:,i)=[];
end
end
The variable i will equal the column number whenever the condition is true, and the corresponding column will be deleted. Note: I deleted the semi-colon at the end of the if-expression.
  4 件のコメント
Mahshad Rabiee
Mahshad Rabiee 2021 年 4 月 22 日
The for loop seems to have created just one column
Scott MacKenzie
Scott MacKenzie 2021 年 4 月 22 日
編集済み: Scott MacKenzie 2021 年 4 月 22 日
Well, I said "something like this". I guess I'm not quite sure what you are trying to do. Maybe you need the loop setup like this:
ma_flexion = MA.data(:,3:30);
ma_flexion_cm=ma_flexion*100;
mini_ma_flexion=min(ma_flexion_cm); % array with 27 elements
maxi_ma_flexion=max(ma_flexion_cm); % array with 27 elements
for i=1:27
if (maxi_ma_flexion(i)-mini_ma_flexion(i))<=(0.5*mini_ma_flexion(i))
ma_flexion_cm(:,i)=[];
end
end
I think you can even do this without the for-loop. Try replacing the last five lines above with this:
conditionLogical = (maxi_ma_flexion-mini_ma_flexion)<=(0.5*mini_ma_flexion);
ma_flexion_cm(:,conditionLogical)=[];

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by