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 件のコメント

dpb
dpb 2019 年 5 月 6 日
Don't do stuff like this with for loops -- MATLAB is MATrix LABoratory -- use the vector facilities!!!

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

 採用された回答

dpb
dpb 2019 年 5 月 6 日

0 投票

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 ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2019 年 5 月 6 日

回答済み:

dpb
2019 年 5 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by