Matlab Subscripted Assignment Dimension Mismatch Matrix Definition

The above code seems to be assuming that the images are two dimensional only. Is this a valid assumption, or are the images (or matrices) 1200x900x3?

The error message is telling you that there is dimension mismatch in your assignment at line

images(:, n) = img(:);

In this case, the code is trying to insert a vector (once the colon is used in img(:)) that is larger than the destination row of images. As you have stated, the size of any image is 1200x900 (so 1080000 elements) BUT images has only been sized a matrix with n rows and 3072=48*64 columns…which is considerably smaller than 1080000. Hence the error.

In the line prior to this assignment, there is an attempt to reshape the data which has been commented out since this line probably generated the error To RESHAPE the number of elements must not change. Since you want to resize, the code should use the imresize command instead:

img = imresize(img,[48 64]);

Using imresize will reduce the image to the 48x64 size which can then be assigned to images.

I am trying to solve the set of 3 differential equations:

dTs(1) = 2*gd*Ts(3)-Ts(1)/TT(j)-aa*(Ts(1)^2+Ts(2)^2)/(TT(j)*GG(j)); dTs(2) = -Ts(2)/TT(j)-aa*(Ts(1)^2+Ts(2)^2)/(TT(j)*GG(j)); dTs(3) = gd*Ts(2)-Ts(3)/TT(j)-aa*Ts(3)*(Ts(1)+Ts(2))/(TT(j)*GG(j))-2*gd*GG(j);

whereas the factors TT(j) and GG(j) are in a loop. When I run the code I receive the error message: "Subscripted assignment dimension mismatch", and It looks like the ODE module fails to converge at t>~100s. In this case I sometimes cut the higher end of tspan (called tx in my code) to times that are smaller than 100 and then the code delivers a solution, but I need the response at larger times too. It might also help to know that the factor aa should be very small (<1e-6) in order for the code to deliver any solution. Here the entire code:

tx=[0 100] for j=1:iGT % Solving the DE for individual relaxation modes j [tt,Ts] = ode23(@fTs,tx,[0 0 0]); T110(:,j)=Ts(:,1); T220(:,j)=Ts(:,2); T120(:,j)=Ts(:,3); endfunction dTs=fTs(t,Ts) dTs = zeros(3,1); % a column vector dTs(1) = 2*gd*Ts(3)-Ts(1)/TT(j)-aa*(Ts(1)^2+Ts(2)^2)/(TT(j)*GG(j)); dTs(2) = -Ts(2)/TT(j)-aa*(Ts(1)^2+Ts(2)^2)/(TT(j)*GG(j)); dTs(3) = gd*Ts(2)-Ts(3)/TT(j)-aa*Ts(3)*(Ts(1)+Ts(2))/(TT(j)*GG(j))... -2*gd*GG(j); end
Categories: 1

0 Replies to “Matlab Subscripted Assignment Dimension Mismatch Matrix Definition”

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *