Error using plot - Vectors must be the same length.
7 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
David Wilson
on 8 Apr 2019
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);
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!