Creating a 50x50 3D matrix composed of 2x1 vectors

2 views (last 30 days)
C_J4995
C_J4995 on 23 Sep 2017
Edited: Rik on 24 Sep 2017
I need to create a 50x50 image with each pixel composed of smaller 2x1 vectors using a 3D matrix. This then needs to be put into a nested for loop in order to have each value altered by a function, The 3D matrix will need to be altered back to 2D though before it can go into the function.
This is the code I have now but I know I am doing something wrong as I keep getting the error that my dimensions do not agree.
y_image=zeros(50,50,14001); %creating empty vector for y image values
X_matrix=rand(50,50,2); %creating 50x50 3D image of X values between 0-1
for row=1:50
for col=1:50
y_image(row,col,:)=R_final*X_matrix(row,col,:);
Y_squeeze=squeeze(y_image(row,col,:));
end
end

Answers (1)

Rik
Rik on 24 Sep 2017
Edited: Rik on 24 Sep 2017
Have a read here and here. It will greatly improve your chances of getting an answer.
I can't understand what it is you want to do.
As for the error you are getting: you are trying to write R_final*X_matrix(row,col,:) to y_image(row,col,:). The right hand side will be of size [size(R_final,1),1,1], while the left hand size is [1,1,14001]. Matlab can be quite tolerant when writing a vector of the wrong size, but the number of elements should be the same at the very least.
So think about what it is you want to do, and first make sure it makes mathematical sense.
And why not do this immediately:
Y_squeeze=squeeze(R_final*X_matrix(row,col,:));

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!