Info

This question is closed. Reopen it to edit or answer.

two picture pixels

2 views (last 30 days)
Pan
Pan on 23 May 2012
Closed: MATLAB Answer Bot on 20 Aug 2021
I want to calculate the corresponding pixels of the two pictures. How can I do? This is my code. clear all; load watch
[m,n,c,f]=size(xw);
fd=zeros(1,324);
a=1; for i=1:325
fd(:,:,:,a)=mean(abs((xw(:,:,:,i+1))-(xw(:,:,:,i))));
a=a+1;
end
but have a error ??? Subscripted assignment dimension mismatch.
Error in ==> detectiontest at 12 fd(:,:,:,a)=mean(abs((xw(:,:,:,i+1))-(xw(:,:,:,i))));

Answers (2)

Geoff
Geoff on 23 May 2012
You are addressing fd(:,:,:,a) as a 4-dimensional array, but it is declared as a 1-dimensional array.
You need to make sure that the shape of the matrix you are assigning to on the left is the same as the shape of the matrix on the right. So you need to look at that call to mean and examine the dimensions of the result (using size). Most easily checked by doing this:
size( mean(abs(xw(:,:,:,1))) )

Image Analyst
Image Analyst on 23 May 2012
fd(:,:,:,a) is a 3D array, while the mean of a 3D array (which is what xw(:,:,:,i+1) is) is a 2D array. For example the mean of a 2D array returns the means of the columns so the mean is always one dimension less than what you took the mean of. So you're trying to assign a 2D array to a 3D array. You need to look up the definition of mean and figure out what you need to pass it to do whatever it is that you want to take the mean of.

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!