Error using plot Vectors must be the same length.
Afficher commentaires plus anciens
I have a problem about using plot... Why i giving a problem? plot(x1,y1,color1,x2,y2,color2...) it's look like true but no its not true. HELP!!!
deger = app.Switch.Value;
a=app.genlik_edit.Value;
b=app.frekans_edit.Value;
c=app.direnc_edit.Value;
f=1/b;
t1=linspace(0,f,256);
t3=linspace(f/2,f,256);
v=a*sin(2*pi*b*t1);
v1=c*sin(2*pi*b*t1);
rect_v = v > 0;
anrect_v = v<0;
rect_v1 = v1 > 0;
l=v*0;
if (deger=="Yarım dalga doğrultucu")
plot(app.UIAxes1,t1(rect_v),v(rect_v),'color',[1,0,0],t3,l,'color',[1,0,0],t1(anrect_v),v(anrect_v),'color',[0,0,1]);
plot(app.UIAxes2,t1(rect_v),v1(rect_v),t3,l,"Color",[0,1,0]);
else
plot(app.UIAxes1,t1(anrect_v),v(anrect_v),t1,abs(v));
plot(app.UIAxes2,t1,abs(v1),"Color",[0,1,0]);
end
Réponses (1)
Cris LaPierre
le 29 Mai 2021
0 votes
The error message is telling you what the problem is - you are trying to plot using a different number of x and y points. In this case, plot doesn't know what to do so it throws an error. It would be helpful to know which line in your code is causing the error.
I suspect either t3 and l don't have the same number of points, or t1 and abs(v1) don't.
3 commentaires
Canberk Utar
le 29 Mai 2021
Canberk Utar
le 29 Mai 2021
Cris LaPierre
le 29 Mai 2021
The error is very clear: when using plot, your x and y vectors must be the same length.
As I suspected, it appears t3 and l do not have the same number of points. These serve as the x and y coordinate pairs, so must be the same length in order to create the coordinate points.
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!