Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Error in plot code

조회 수: 3 (최근 30일)
Ayesha
Ayesha 2014년 2월 15일
마감: MATLAB Answer Bot 2021년 8월 20일
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');

답변 (1개)

Walter Roberson
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
Ayesha
Ayesha 2014년 2월 15일
Here's the complete set. I understand what you're saying and I've for the problem but all in vain. It's kind of confusing to me because the code is running fine when I'm using snr operation instead of minus whereas its not otherwise.
name = 'piece-regular';
n = 1024;
x0 = load_signal(name,n);
x0 = rescale(x0);
sigma = .04;
x = x0 + sigma*randn(size(x0));
mulist = linspace(.1,3.5,31);
err = zeros(1,length(mulist));
for i = 1:length(mulist)
a1=x-x0;
err(i) = abs(a1);
end
Walter Roberson
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!

Translated by