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

2 views (last 30 days)
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?

Answers (1)

Torsten
Torsten on 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 Comments
Torsten
Torsten on 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 on 19 Mar 2023
awesome yes that part is now working but when i do maxerror=max(abs(yactual-yvar)) it gives an erorr

Sign in to comment.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!