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

1 次查看(过去 30 天)
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?

回答(1 个)

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

请先登录,再进行评论。

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by