Filter löschen
Filter löschen

error when using plot

2 Ansichten (letzte 30 Tage)
Damien
Damien am 11 Nov. 2022
Kommentiert: Damien am 11 Nov. 2022
Not sure why i keep getting error using plot. vectors must be the same length, as the data all have a 2065x1 and im plotting x=[1:10].
aapl = load('aapl.txt');
msft = load('msft.txt');
qcom = load('qcom.txt');
wfc = load('wfc.txt');
aapl_mean = mean(aapl(:));
msft_mean = mean(msft(:));
qcom_mean = mean(qcom(:));
wfc_mean = mean(wfc(:));
similarity_aapl_msft = ((aapl - aapl_mean)'*(msft - msft_mean))/(sqrt(sumsqr(aapl - aapl_mean))*sqrt(sumsqr(msft - msft_mean)));
similarity_aapl_qcom = ((aapl - aapl_mean)'*(qcom - qcom_mean))/(sqrt(sumsqr(aapl - aapl_mean))*sqrt(sumsqr(qcom - qcom_mean)));
similarity_aapl_wfc = ((aapl - aapl_mean)'*(msft - wfc_mean))/(sqrt(sumsqr(aapl - aapl_mean))*sqrt(sumsqr(wfc - wfc_mean)));
if similarity_aapl_wfc > similarity_aapl_qcom && similarity_aapl_wfc > similarity_aapl_msft
display("WFC");
elseif similarity_aapl_msft > similarity_aapl_qcom
display("Microsoft");
else
display("QCom");
end
x = [1 2 3 4 5 6 7 8 9 10];
plot(x, aapl,'r',x,msft, 'b',x,qcom,'g', x,wfc,'m');
  1 Kommentar
Image Analyst
Image Analyst am 11 Nov. 2022
You forgot to attach the 4 txt files.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 11 Nov. 2022
the data all have a 2065x1
That implies that
aapl = load('aapl.txt');
aapl is size 2065 x 1.
x = [1 2 3 4 5 6 7 8 9 10];
x is length 10
plot(x, aapl,'r',x,msft, 'b',x,qcom,'g', x,wfc,'m');
x is length 10 but aapl is length 2065. You cannot plot 10 x values but 2065 y values.
Perhaps you want
mask = 1:length(x);
plot(x, aapl(mask),'r',x,msft(mask), 'b',x,qcom(mask),'g', x,wfc(mask),'m');
  1 Kommentar
Damien
Damien am 11 Nov. 2022
thank you so much I've been working on this all day, new to matlab and excited to learn from the community. Thank you so much again!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by