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.
0 个评论
采纳的回答
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!