Running a loop through an array of matrices
Show older comments
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!
Answers (1)
the cyclist
on 5 Aug 2011
0 votes
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.
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!