Creating a 50x50 3D matrix composed of 2x1 vectors
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Rik
on 24 Sep 2017
Edited: Rik
on 24 Sep 2017
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,:));
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!