loop in a column to calculate max and min in a certain interval

i have a column that has 200 values of length for each volume. and there can be n no. of volumes. so i need to calculate the maximum and minimum of lengths for each volume and plot volume(vs)minlength and volume(vs)maxlength in the same plot. please suggest a loop and how to apply it. help is much appreciated.

2 Comments

What do you mean by volume? Can you provide an example? The problem is not clear to me.
sud's "Answer" moved here:
hi! i will attach a file. so its 1st column is volume and 16th column is length.

Sign in to comment.

Answers (2)

Let V be your volume and A be other column.
[c,ia,ib] = unique(V) ;
N = length(c) ;
iwant = zeros(N,1) ;
for i = 1:length(c)
iwant(i) = mean(A(ib==i)) ;
end

1 Comment

Hi. It is working. thanks but maybe i didnt put my problem correctly. I want to apply a loop for thia program written below! (after every 200 lengths):
IdlCatalogue_Dir='C:\Users\yadav\Desktop\IDL_routine\OUTPUT_FILE\ROSETTE_S2_r5\';
File = 'ROSETTE_S2_r5_GeometricData.csv';
FF = fullfile(IdlCatalogue_Dir,File);
Type = strrep(File, '_GeometricData_TOT.csv', '');
Type = strrep(Type,'_','\_');
data = load(FF);
deq = data(end-199:end,16);
for i=1:length(deq)
minimum(i)=min(deq(1:i));
% i'th of maximum would be the max upto ith interval of deq .
end
x=1:1:200;
figure()
plot(x,maximum);
hold on;
plot(x,minimum); set(gca,'xscale','log');
xlabel('number of projections')
ylabel('Deq(µm)')
title('Variation of Max Deq and Min Deq with number of projections')

Sign in to comment.

Perhaps this will help...
data=readtable('ROSETTE_S2_R5_GeometricData.csv');
[volumes]=unique(data{:,1});
out=nan(2,length(volumes));
for i=1:length(volumes);
out(1,i)=min(data{data{:,1}==volumes(i),16});
out(2,i)=max(data{data{:,1}==volumes(i),16});
end
figure;
plot(volumes,out(1,:),...
volumes,out(2,:));

9 Comments

Hi. It is working. thanks but maybe i didnt put my problem correctly. I want to apply a loop for thia program written below! (after every 200 lengths):
IdlCatalogue_Dir = 'C:\Users\yadav\Desktop\IDL_routine\OUTPUT_FILE\ROSETTE_S2_r5\'; %path of folder File = 'ROSETTE_S2_r5_GeometricData.csv'; %name of file FF = fullfile(IdlCatalogue_Dir,File); Type = strrep(File, '_GeometricData_TOT.csv', ''); Type = strrep(Type,'_','\_'); data = load(FF);
deq = data(end-199:end,16);
% n=1:1:length(deq(1:100)); % n becomes [1,10,20,...400] for i=1:length(deq) maximum(i)=max(deq(1:i)); % i'th of maximum would be the max upto ith interval of deq . end
for i=1:length(deq) minimum(i)=min(deq(1:i)); % i'th of maximum would be the max upto ith interval of deq . end
x=1:1:200; figure() plot(x,maximum); hold on; plot(x,minimum); set(gca,'xscale','log'); xlabel('number of projections') ylabel('Deq(µm)') title('Variation of Max Deq and Min Deq with number of projections')
if true
% code
end
Please select the text before clicking code
Hi. It is working. thanks but maybe i didnt put my problem correctly. I want to apply a loop for thia program written below! (after every 200 lengths):
IdlCatalogue_Dir = 'C:\Users\yadav\Desktop\IDL_routine\OUTPUT_FILE\ROSETTE_S2_r5\'; %path of folder File = 'ROSETTE_S2_r5_GeometricData.csv'; %name of file FF = fullfile(IdlCatalogue_Dir,File); Type = strrep(File, '_GeometricData_TOT.csv', ''); Type = strrep(Type,'_','\_'); data = load(FF);
deq = data(end-199:end,16);
% n=1:1:length(deq(1:100)); % n becomes [1,10,20,...400] for i=1:length(deq) maximum(i)=max(deq(1:i)); % i'th of maximum would be the max upto ith interval of deq . end
for i=1:length(deq) minimum(i)=min(deq(1:i)); % i'th of maximum would be the max upto ith interval of deq . end
x=1:1:200; figure() plot(x,maximum); hold on; plot(x,minimum); set(gca,'xscale','log'); xlabel('number of projections') ylabel('Deq(µm)') title('Variation of Max Deq and Min Deq with number of projections')
it should look something like this but this figure has only for one length(over 200 rows) but i want the same figure for like 9 volumes..
Sorry but I can't help you if you don't format your code correctly. I mean, you can see it yourself after posting. Try pasting the format you gave me into MATLAB and run it...
hi. so sorry for the bad format but i did try to select it and code it. i dont know why is it not taking the form of code!
I did some formatting and wrote this for you (see attached). All values are stored in maximum and minimum. You can choose which curve to plot by changing the variable id.
If you need anything else, please format the post correctly.

Sign in to comment.

Tags

Asked:

sud
on 28 May 2018

Commented:

on 28 May 2018

Community Treasure Hunt

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

Start Hunting!