Running a loop through an array of matrices
显示 更早的评论
OK...now here is the second part of the thing...!
I have two arrays of size (576*576*2) and (576*576*5)....one containing 2 matrices of images that were 576*576 and the other containing 5 similar images. For each matrix in the first array, I need to calculate the matrix in the other array that has the lowest mean error. How do I exactly do that? I sorta have the loops figured out!
This is how my code looks for one value of the first TEST array..
min=100*sum(576*1); for i=1:4
if sum(testa(:,:,1)-traina(:,:,i))<min min=(sum(testa(:,:,1)-traina(:,:,i))) disp(val) val=i end end disp(val)
However, it turns out that val is not changing after the first case. It always gives me the answer as 1, when it should give me an answer three for testa(:,:,2). Both arrays contain
M-B*A*B' where A is the imread of the image and B is its dct2 value.
THanks a lot you guys!
回答(1 个)
the cyclist
2011-8-5
0 个投票
In your if statement, that sum(...) is going to result in a vector of length 576, because it is going to sum your array down each column. Instead, try using sum(sum(...)) there.
类别
在 帮助中心 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!