Error using plot - Vectors must be the same length.

2 vues (au cours des 30 derniers jours)
Bob
Bob le 7 Avr 2019
Modifié(e) : Bob le 8 Avr 2019
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.

Réponse acceptée

David Wilson
David Wilson le 8 Avr 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);
  1 commentaire
Bob
Bob le 8 Avr 2019
Modifié(e) : Bob le 8 Avr 2019
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

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by