MATLAB: Re-running a for loop for 100s of different ranges

forfor looploops

Hi experts hope you can help me 🙂
I would like to re-run a 'for' loop for 100s of different ranges. the loop is below in the code. I believe it will need a loop in a loop but I don't know how to do this, I have a list of the ranges (x and y values that make the range), but how do I implement this so that it does the loop for k=58:69 then again for K=78;89 then for k=90:102 ect, (no pattern in rages). Hope this is clear what am trying to do. any input would be much appreciated.
%Clearing and formatting
clear all;
close all;
format long;
%getting range of each scan
Scan_ranges = xlsread('aCopy of spray 144_plume scans','B:C');
%creating results file
z=[];
% control loop to process all files in the range k
for k = x:y
%Importing data
open_file = csvread((sprintf('C1charlie %d.csv', k)),5,0);
%Seperating data
Time = open_file(:, 1);
Ampl=open_file(:,2);
%Seperating positive and negative data for time and amplitude
ind_pos = find(Time>0);
ind_neg = find(Time<0);
Ampl_pos= Ampl(ind_pos);
Ampl_neg= Ampl(ind_neg);
%Finding the standared deviation of the amplitudes and muiliplying by 1e4
SD_I_pos = std(Ampl_pos)*1e4;
SD_I_neg = std(Ampl_neg)*1e4;
%Choosing the smaller of the two amplitudes
if SD_I_pos>SD_I_neg
z = [z mean(Ampl_neg)*1e4];
else
z = [z mean(Ampl_pos)*1e4];
end
end

Best Answer

You should work on a much simpler code to understand how it works. Here is an example..
ranges = [3, 8; 2, 5; 1,7] ; % 3 ranges from your Excel file.
for rId = 1 : size(ranges, 1) % Outer loop.
for x = ranges(rId,1) : ranges(rId,2) % Inner loop.
fprintf('%d,', x) ;
end
fprintf('\n') ;
end
This code outputs:
3,4,5,6,7,8,
2,3,4,5,
1,2,3,4,5,6,7,