subsetting a three dimensional array from elements in a vector
Show older comments
Hi,
I am new to Matlab and not an experienced programmer. I have a color photograph im1 (jpeg) and I want to sample the RGB values every 1cm across the image. I found that 34px is roughly 1cm on my own printer (I took the 'standard' of 37.78px per cm and experimented with my own equipment).
So for my whole image array (400 x 20 x 3) I would like to return the rgb values every 34th row. I set up a simple array:
b = 1:34:400
b = b'
This gives me a 12x1 vector which corresponds to the rows in im1 I would like to sample. But as stupid as it sounds I do not know how to do this. I tried setting up conditional statements with multiple conditions:
for i = 1:x %where x is number of rows in im1
if i == 1 | i == 34 | i == 68 | i == 102 | i == 136 | i == 170 | i == 204 | i == 238 | i == 272 | i == 306 | i == 340 | i == 374
newarray = im1(i,:,:);
end
end
Not only is this extremely unwieldy, it also doesn't work. This seems basic but I can't figure out what to do. There must be a better way -- can anyone help?
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!