insert numbers 1-21 in rows 1-21 of a column

%I don't understand the difference. This works fine:
imageInformation = zeros(21, 4);
imageInformation(:,1) = rem((0:size(imageInformation,1)-1)',21)+1;
%Inserts numbers 1-21 in first column of every row of the matrix.
%...so how come this doesnt work:
images = zeros(640,480,3,21);
images(:,:,:,1) = rem((0:size(images, 4)-1)',21)+1;
%I get error message:
Subscripted assignment dimension mismatch.
Error in loadImages (line 42)
images(:,:,:,1) = rem((0:size(images, 4)-1)',21)+1;
%How can I get it to work?

Answers (1)

What are you trying to do? One way to think of a 4 dimensional image is to think of a series of color frames (3D images) with the 4th dimension being time (the frame number). Using that paradigm, what do you want to have the values 1 to 21? Do you want the top 21 (out of 640) rows of each color frame to be a grayscale ramp, from the top line having all 1's in R, G, and B channels, to row 21 having 21s in every column and every color channels, and then repeat this pattern for all 21 frames?

1 Comment

Thanks for responding! What I want to do is have an array of 21 images, and number them 1-21. Should I approach this in another way?

Sign in to comment.

Products

Asked:

on 18 Nov 2012

Community Treasure Hunt

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

Start Hunting!