Info

此问题已关闭。 请重新打开它进行编辑或回答。

two picture pixels

3 次查看(过去 30 天)
Pan
Pan 2012-5-23
关闭: MATLAB Answer Bot 2021-8-20
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))));

回答(2 个)

Geoff
Geoff 2012-5-23
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 2012-5-23
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.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by