Resetting for loop counter
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
David Hill
2022년 4월 5일
tactarray(:,sum(tactarray<1)>0)=[];
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!