Info
此问题已关闭。 请重新打开它进行编辑或回答。
Error in plot code
3 次查看(过去 30 天)
显示 更早的评论
The code is very simple where I have to plot the denoising error as a function of mu. how ever I am getting error at
err(i) = abs(a1);
with the message : In an assignment A(I) = B, the number of elements in B and I must be the same. I see absolutely nothing that could logically go wrong but still, what's wrong?
mulist = linspace(.1,3.5,31);
err = zeros(1,length(mulist));
for i = 1:length(mulist)
a1=x-x0;
err(i) = abs(a1);
end
figure;
plot(mulist,err, '.-'); axis('tight');
set_label('\mu', 'SNR');
0 个评论
回答(1 个)
Walter Roberson
2014-2-15
You have not show us x or x0. One or both of them are vectors (or arrays), and you are trying to store abs() of the vector arithmetic inside the single element err(i) .
Notice that your "for i" loop goes to length of mulist but "a1=x-x0" does not depend upon mulist at all, so each a1 value would be exactly the same.
2 个评论
Walter Roberson
2014-2-15
snr() takes in a vector and returns a single value, the signal to noise ratio.
minus of two vectors returns another vector the length of the originals.
[9, 5, 2] - [4, 11, 21] = [5, -6, -19]
Are you trying to find the "distance" between the two vectors? If so then minus is not the right operation for that. For that you would want something like the Euclidean Distance,
sqrt(sum((x-x0).^2))
Perhaps, though, you are trying to find the correlation of the two vectors. Or perhaps you are trying to find the lag between them. Or perhaps you are trying to find a measure of whether they are considered to be drawn from the same distribution. Or... lots of things you might have intended. What were you thinking that minus would do for you?
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!