From: Frédéric Bergeron on
"Maxx Chatsko" <chatskom(a)chemimage.com> wrote in message <i1fmgd$hs8$1(a)fred.mathworks.com>...
> Hello all,
> Suppose I have a double with 15 rows. I want to take data from the first four lines in every set of five and skip the fifth row. How can I express this in a for loop? Thanks
> Maxx

Hi,
maybe a for loop isn't necessary. Try this:

a=your data;
index=1:size(a,1);
b=a(rem(idx,5)~=0,:);

I think this is one of the solution.
Fred
From: Maxx Chatsko on
"Ashish Uthama" <first.last(a)mathworks.com>
>
> Do you need a FOR loop? It would have helped to give more context.

Yeah good point. Sorry. So I have an array that holds spectral data from several ROIs, where each row represents an ROI. The user specifies a number of spectra and the program goes through a number of images, takes ROIs (spectra), and plots them. The problem with our program was if the user requested 22 spectra (or a number that wasn't a multiple of 5) from 5 images, the program plotted only 20 spectra (it was rounded to a clean number, so 4 ROIs from each image).
Now it takes one extra ROI from 2 images, which is the remainder (22-20). Instead of just taking the next 12 spectrum in the array I want to take 4 from each image, thus the skipping one row in every 5 rows. Skipping the row will make each image count more uniformly towards the overall average of all spectra displayed.
The number of spectra requested by the user will vary, so the remainder could be 1,2,3 etc. The number of images being processed will also change. I have the variables set, so that shouldn't be a problem.
From: Maxx Chatsko on
So I guess my real question isn't about for loops, but about passing in rows of data from an array of data into an array of zeros. If I have

zero_array(min:max,:)=data_array(???)

is there a way to skip every fourth row in five when passing the data into the new array?
Maxx
I'll be more precise next time. Promise.
From: Ashish Uthama on
On Mon, 12 Jul 2010 14:53:20 -0400, Maxx Chatsko <chatskom(a)chemimage.com>
wrote:

> "Ashish Uthama" <first.last(a)mathworks.com>
>> Do you need a FOR loop? It would have helped to give more context.
>
> Yeah good point. Sorry. So I have an array that holds spectral data
> from several ROIs, where each row represents an ROI. The user specifies
> a number of spectra and the program goes through a number of images,
> takes ROIs (spectra), and plots them. The problem with our program was
> if the user requested 22 spectra (or a number that wasn't a multiple of
> 5) from 5 images, the program plotted only 20 spectra (it was rounded to
> a clean number, so 4 ROIs from each image). Now it takes one extra
> ROI from 2 images, which is the remainder (22-20). Instead of just
> taking the next 12 spectrum in the array I want to take 4 from each
> image, thus the skipping one row in every 5 rows. Skipping the row will
> make each image count more uniformly towards the overall average of all
> spectra displayed.
> The number of spectra requested by the user will vary, so the
> remainder could be 1,2,3 etc. The number of images being processed will
> also change. I have the variables set, so that shouldn't be a problem.

That helps.

See if this makes sense (I get the feeling I might have complicated this
beyond needed.. :()

nImages=7;
nRoisPerImage=11;

%random data: (5 is the number of columns in your ROI/spectra
data=repmat((1:nImages*nRoisPerImage)', [1 5]);

nRoisReq = 17;

%i.e floor(17/7) ROIs from each image with mod(17,7) ROIs more needed


%full rois (floor(17/7))
RoisPerImageReg = repmat(floor(nRoisReq/nImages),[nImages,1]);

%we need to pick some additional rois, lets do that by picking up 1 more
%ROI for the first mod(17,7) images.
additionalRois = mod(nRoisReq,nImages);
RoisPerImageReg(1:additionalRois)= RoisPerImageReg(1:additionalRois) +1;

%Now lets create the start and stop indices into the main data array to
%extract these rois
startingInds = 1:nRoisPerImage:size(data,1);
startingInds = startingInds';
endingInds = startingInds+RoisPerImageReg-1;

%preallocate output
extractedData = zeros(nRoisReq,5);

%marker marks the section of the output (extractedData) that we want to
%write to.

markerStart=1;
for imageInd = 1:nImages
markerEnd = markerStart+RoisPerImageReg(imageInd)-1;
extractedData(markerStart:markerEnd,:) = ...
data(startingInds(imageInd) : endingInds(imageInd),:);
markerStart = markerEnd+1;
end
From: Maxx Chatsko on
"Ashish Uthama" <first.last(a)mathworks.com>

A little complicated, so I did not use it. BUT, you got me thinking in the right direction and you and I figured it out. Thanks Ashish!
Maxx