Error using plot - Vectors must be the same length.

조회 수: 7 (최근 30일)
Bob
Bob 2019년 4월 7일
편집: Bob 2019년 4월 8일
Hi
I want to plot my correlaton values and diffrence between two values from which correlation was correlated but keep getting errors:
L = length(A) - 300;
B = zeros(L, 1);
for i = 1 : L
cc = corrcoef(A(i:i+300), S(i:i+300))
B(i) = cc(2,1);
end
plot(B);
Z=A-S;
figure(2)
plot(B,Z);
or
plot(cc,Z);
Is it possible to do in matlab ? I tried and error appears in command window:
Error using plot
Vectors must be the same length.
Any help would be appriciable.

채택된 답변

David Wilson
David Wilson 2019년 4월 8일
It's a little hard to second guess what you are trying to do, but it seems that you need to pad vector B with zeros or something (such as NaN) to make it the same length as the original A.
When you do the correlation now, you can just dump/ignore the final 300 values.
A = randn(1e3,1); % set some random data
S = randn(1e3,1); % set some more
L = length(A) - 300;
B = NaN(length(A), 1); % note B is pre-allocated same a A
for i = 1 : L
cc = corrcoef(A(i:i+300), S(i:i+300));
B(i) = cc(2,1);
end
plot(B);
Z=A-S;
figure(2)
plot(B,Z);
  댓글 수: 1
Bob
Bob 2019년 4월 8일
편집: Bob 2019년 4월 8일
Hi David,
It worked, However, how Can I plot B values at X axis and Z values at Y axis and in diffrent colors ?
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by