er = rms_error(A1,A2)
here A1, A2 are original and reconstructed data. The order of A1,A2 doesn't matter, interchanging them will also give same result.
"numel(A1)" looks nicer than "size(A1(:),1)".
The comparison of "size(A1)~=size(A2)" crashes, if the number of dimensions differs. Therefore this is smarter: "~isequal(size(A1), size(A2))"
MATLAB = MATrix LABoratory
er = A1 - A2;
er = sqrt( (er(:)' * er(:)) / length(er(:)) );
Advantages: faster, shorter, works with arbitrarily sized A1/A2, works with complex data, too.
modified to display proper message while matrix dimension mismatch.
No update in the code, only changed the description of code
for loops were eliminated for fast implementation.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.