How can I filter through my data using a for loop?

15 views (last 30 days)
Hello,
I'm trying to take data from an excel sheet and use a for loop to take only the data that fits the criteria. My understanding is that by taking the values from the excel sheet from column 2 and using that as a filter, I can then say for only those values in column three should the data be stored in a matrix. However, I am not getting filtering to occur. I am not sure what I am doing wrong here. Here is my attached code. Thank you for your help in advance!
clear
clc
filename = 'PIVtest.xlsx'; %PIV excel file CHANGE!
%framerate = 3.96; %fps CHANGE!
%scalefactor = 0.973; %um/pixel CHANGE!
List = xlsread(filename,1);
Track = List(:, 1);
Position = List(:, 2);
Velocity = List(:, 3);
%Particle=zeros(1,size(Velocity,1));
ID=0;
%id=cell(1,size(Track,1));
%X0=Position(1);
%Frame0=Frame(1);
for k = 1:size(Track,1)
if Position(k)<100
k = k+1;
else
%id(k,:)=Track(k);
vel(k,:)=Velocity(k);
%A = List(:,vel(k))
end
end
%figure
%plot(Position,vel, 'r . ', 'MarkerSize',12)
%hold on
%title('PIV Example')
%xlabel('Position')
%ylabel('Velocity (\mum)')
  1 Comment
dpb
dpb on 6 May 2019
Don't do stuff like this with for loops -- MATLAB is MATrix LABoratory -- use the vector facilities!!!

Sign in to comment.

Accepted Answer

dpb
dpb on 6 May 2019
filename = 'PIVtest.xlsx';
data=xlsread(filename);
PLimit = 100; % set position limit to screen
TPV=data(data(:,2)<PLimit,:); % save data T(rack)P(posn)V(elocity) for P<PLimit
...
Do what want/need with results from here...

More Answers (0)

Community Treasure Hunt

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

Start Hunting!