Error using plot - Vectors must be the same length.

7 次查看(过去 30 天)
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