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

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 个评论

Don't do stuff like this with for loops -- MATLAB is MATrix LABoratory -- use the vector facilities!!!

请先登录,再进行评论。

 采纳的回答

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...

更多回答(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!

Translated by