When running code it returns >> pp01 Error using plot Error in color/linetype argument. Error in pp01 (line 33) plot(t(:),​z(:,1),'W'​,t(:),z(:,​2),'F')

4 Ansichten (letzte 30 Tage)
function pp01
clear
global As Qt g A c
As=15;
Qt=10;
g=9.81;
A=(121/64)*pi;
c=0.02;
z1_initial=10;
z2_initial=25;
N=1000;
h=0.5;
t=zeros(N,1);
z=zeros(N,2);
t(1)=0;
z(1,1)=z1_initial;
z(1,2)=z2_initial;
for n=1:N-1
t(n+1)=t(n)+h;
z(n+1,:)=z(n,:)+h*f(t(n),z(n,:));
z(n+1,:)=z(n,:)+0.5*h*(f(t(n),z(n,:))+f(t(n+1),z(n+1,:)));
end
%plot(t(:),z(:,1),'W',t(:),z(:,2),'F')
Figure 2
Plot(z(:,1),z(:,2))
[t,z];
return
function dzdt=f(~,z)
global As Qt g A c
%dzdt(1)=z(2);
%dzdt(2)=-z(1);
dzdt(1)=(1/As)*(z(2)-Qt);
dzdt(2)=-g*(A/2)*(z(1)+(c*abs(z(2))*z(2)));
return

Antworten (1)

Walter Roberson
Walter Roberson am 20 Apr. 2019
'W' is valid as a code for White but 'F' is not a color abbreviation and is not a marker shape code. Valid codes are
  • b: blue
  • c: cyan
  • d: diamond marker
  • g: green
  • h: hexagon marker
  • k: black
  • m: magenta
  • o: circle marker
  • p: pentagram marker
  • r: red
  • s: square marker
  • v: down triangle marker
  • w: white
  • x: x marker
  • y: yellow
  • *: * marker
  • +: + marker
  • . : dot marker
  • ^: upward triangle marker
  • <: left triangle marker
  • >: right triangle marker
  • - and : are used for line styles
  2 Kommentare
Lucy Raistrick
Lucy Raistrick am 20 Apr. 2019
That seems to have fixed an issue but now this error is appearing
>> pp01
Undefined function or variable 'Figure'.
Error in pp01 (line 35)
Figure 2
Walter Roberson
Walter Roberson am 20 Apr. 2019
MATLAB has been case sensitive for quite a while now. The graphics routines all start with lower case letters. figure and plot not Figure and Plot

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by