MATLAB loop through certain integers and in the order that I specify v2

72 views Asked by At

The normal loop is

   for i=1:50

   end

but I want to execute the loop through certain integers in 4 different array simultaneously and in the order that I specify. So in the first loop, Matlab would take the first integer from r1, r2, c1, c2. Then for the second loop, Matlab would take the second integer from r1, r2, c1, c2.

For r1 = [1128, 1128, 1128, 1128, 1128, 1128, 1128, 1128];
    r2 = [1148, 1148, 1148, 1148, 1148, 1148, 1148, 1148];
    c1 = [776, 776 + 1280, 776 + 1280*2, 776 + 1280*3, 776 + 1280*3 + 994, 776 + 1280*4 + 994, 776 + 1280*5 + 994, 776 + 1280*6 + 994, 776 + 1280*7 + 994];
    c2 = [792, 792 + 1280, 792 + 1280*2, 792 + 1280*3, 792 + 1280*3 + 994, 792 + 1280*4 + 994, 792 + 1280*5 + 994, 792 + 1280*6 + 994, 792 + 1280*7 + 994];
    a1_raw = imread('T:\SST\...\pinhole_1-8_6s', 'PixelRegion', {[r1, r2], [c1, c2]});
End

Also, I'd like a1_raw to change every time the loop loops so that at the end of the loop I should have 8 different "a1_raws". How can I do that in MATLAB?

1

There are 1 answers

2
Shai On BEST ANSWER

use a single index for all arrays

n = numel( r1 ); %// assuming r2, c1 and c2 all have same number of elements
a1_raw = cell( 1, n ); %//pre-allocate
for ii = 1:n
    r1i = r1(ii);
    r2i = r2(ii);
    c1i = c1(ii);
    c2i = c2(ii);
    a1_raw{ii} = imread('T:\SST\...\pinhole_1-8_6s', 'PixelRegion', {[r1i, r2i], [c1i, c2i]});
end