it says it cant plot because my vectors aren't the same size but they are

2 visualizzazioni (ultimi 30 giorni)
yvec=[6.67 17.33 42.67 37.33 30.10 29.31 28.74];
xvec=[0 6 10 13 17 20 28];
xvar=0:.001:28;
yvar=P_N(xvec,yvec,xvar);
plot(xvar,yvar,xvec,yvec,'r*')
trying to run this code but it says
Error using plot
Vectors must be the same length. anyone know how to fix this?

Risposte (1)

Torsten
Torsten il 19 Mar 2023
Check whether size(yvar) equals size(xvar).
I think this cannot be true because the following code works:
yvec=[6.67 17.33 42.67 37.33 30.10 29.31 28.74];
xvec=[0 6 10 13 17 20 28];
xvar=0:.001:28;
%yvar=P_N(xvec,yvec,xvar);
yvar = rand(size(xvar));
plot(xvar,yvar,xvec,yvec,'r*')
  3 Commenti
Torsten
Torsten il 19 Mar 2023
You call P_N as
yvar=P_N(xvec,yvec,xvar);
and the function is given as
function [out] = P_N(xvar,xvec,yvec)
Do you see that the inputs in the call to P_N are in the wrong order ?
allison
allison il 19 Mar 2023
awesome yes that part is now working but when i do maxerror=max(abs(yactual-yvar)) it gives an erorr

Accedi per commentare.

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by