Resetting for loop counter
Mostra commenti meno recenti
I'm trying to write a program to help filter data. What I would like to do is be able to import data from an excel spreadsheet, look through each column of data to determine if there are values less than 1. If so, I would like to remove the column because I don't need the data for that sensor. However, the issue I'm running into is that when I delete the column in the for loop the counter doesn't take that into account so it misses columns. For example. I know that the data set I've been running the code with should have the first column removed. Once it is removed the index value increases to 2 so it misses the original second column since that is now column 1 after the first is deleted. Is there a work around to subtract one from the counter everytime a column is deleted in the matrix?
tactarray = ManikinVestCutLeftShoulder; %creates matrix from imported TactArray pressure data
numElement = size(tactarray,2); %extracts number of sensor elements from the number of columns in dataset
%for each element it should count the number of cells where pressure is
%less than 1kPa. If numGreaterThan1 is greater 0 it should delete the column.
numElementFinal = numElement; %recalculate the total number of columns remaining after filtering data
for e = 1:numElement
A = tactarray(:,e);
numGreaterThan1 = sum(A<1);
if numGreaterThan1 > 0
tactarray(:,e) =[];
numElementFinal = numElement-1;
else
end
end
Risposta accettata
Più risposte (1)
David Hill
il 5 Apr 2022
tactarray(:,sum(tactarray<1)>0)=[];
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!