# How to pick the minimum value from column1(flowrate) with respect to each value from column2(head)?

1 view (last 30 days)
muhammad choudhry on 2 Mar 2022
Hi,
I have a data in 2 columns. Column 1 is flowrate and column 2 is head. Head values are like 0,0,0.01,0.01, and up to 0.5 but with respect to head values flow rate values changing even with at the same head
for example:
0.5 5.04
0.5 5.15
0.5 5.12
etc etc
I want to plot the graph of head over flowrate by specifying that for each head value plot the minimum flowrate value for example if at 0.5 head flowrate have a range from (5.04-5.12) it will plot 5.04... This way I can ignore the discrepencies and analyse the data.
Below is the code for only plotting the data but not with the minimum flow rate value, I am also attaching the csv file. Your help will be much appreciated.
Code so far:
files = ['F:\19-CFD_Analysis\LES\K-Equation\110_Outlet\Fine_1\S_Curve\S-Curve.csv'];
x=a(:,1);
y=a(:,2)*1000;
plot(x,y,'*')
xlim([0 6])
ylim([0 500])

David Hill on 2 Mar 2022
a=[];
u=unique(s(:,2));
for k=1:length(u)
m=min(s(s(:,2)==u(k),1));
a=[a,m(1)];
end
plot(u,a);
##### 3 CommentsShow 1 older commentHide 1 older comment
David Hill on 2 Mar 2022
This is better.
u=unique(s(:,2));
a=zeros(1,length(u));%preallocate
for k=1:length(u)
a(k)=min(s(s(:,2)==u(k),1));%s(:,2)==u(k) finds all column 2 values equal to u(k), then min(s(that,1)) finds min of all column 1 rows that correspond
end
plot(u,a);
muhammad choudhry on 2 Mar 2022
THANKS ALOT FOR THE EXPLANATION