having error "Attempt to execute SCRIPT plot as a function: C:\Azam\non-linear\files\plot.m" in matlab when I want to plot
Show older comments
Hi every one.
I want to plot s/th in matlab, I don't know why it plots sometimes and some time it doesn't plot and give me this error"
"Attempt to execute SCRIPT plot as a function:
C:\Azam\non-linear\files\plot.m
Error in goal11 (line 44)
plot(ys(:,1),ys(:,2))"
I will be pleased if every one can help me. because this probmel occurs for me very much recently in different mfiles.
Thanks
My code is:
clear all; close all; clc
%f = @(t,V) [-1-V(1).^2; -V(2)];
%f = @(t,V) [10*V(2);0];
%f= @(t,V) [1.5*V(1)+2*V(2);-2*V(1)-0.5*V(2)];
f1=@(t,V)[-1.5*V(1)+V(2);(V(1)+V(2))*sin(V(1))-3*V(2)];
f2=@(t,V)[-2*V(1)-V(2).^3;(V(1)-V(2))];
v1 = linspace(-10,10,50);
v2 = linspace(-10,10,50);
[x,y] = meshgrid(v1,v2);
size(x)
size(y)
u = zeros(size(x));
v = zeros(size(y));
s = zeros(size(x));
z = zeros(size(y));
t=0; % we want the derivatives at each point at t=0, i.e. the starting time
for i = 1:numel(x)
Yprime = f1(t,[x(i); y(i)]);
Yprim = f2(t,[x(i); y(i)]);
u(i) = Yprime(1);
v(i) = Yprime(2);
s(i)= Yprim(1);
z(i) = Yprim(2);
end
figure(1)
quiver(x,y,u,v,'r');
hold on;
quiver(x,y,s,z,'b');
%figure(gcf)
xlabel('V1')
ylabel('V2')
axis tight equal;
figure(2)
for y10=[-2 5 10 16 20]
for y20 = [-4 1 7 13 20]
[ts,ys] = ode45(f1,[0,13],[y10;y20]);
[ts1,ys1] = ode45(f2,[13,16],[y10;y20]);
[ts2,ys2] = ode45(f1,[16,20],[y10;y20]);
[ts3,ys3] = ode45(f2,[20,22],[y10;y20]);
[ts4,ys4] = ode45(f1,[22,35],[y10;y20]);
[ts5,ys5] = ode45(f1,[35,40],[y10;y20]);
plot(ys(:,1),ys(:,2))
hold on;
plot(ys(1,1),ys(1,2),'bo') % starting point
hold on;
plot(ys(end,1),ys(end,2),'ks') % ending point
hold on;
% plot(ys1(:,1),ys1(:,2))
% plot(ys1(1,1),ys1(1,2),'bo') % starting point
% plot(ys1(end,1),ys1(end,2),'ks') % ending point
% hold on;
% plot(ys2(:,1),ys2(:,2))
% hold on;
% plot(ys3(:,1),ys3(:,2))
% hold on;
% plot(ys4(:,1),ys4(:,2))
%
% hold on;
% plot(ys5(:,1),ys5(:,2))
end
end
Answers (1)
Steven Lord
on 10 Apr 2019
1 vote
Rename the file C:\Azam\non-linear\files\plot.m to something else. While it exists in the current directory or in a directory on the MATLAB search path with that name, you will not be able to use the built-in plot function.
2 Comments
azam ghamari
on 10 Apr 2019
Hakan Özhan
on 13 Dec 2020
Edited: Hakan Özhan
on 13 Dec 2020
Thank you both of you :)
Categories
Find more on Clocks and Timers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!