Plotting values by defining a function plotter
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Kunal Jain
am 26 Feb. 2022
Kommentiert: Kunal Jain
am 26 Feb. 2022
Getting error in a function named plotter.
ERROR:
plotter( 1,8,1 )
Index in position 1 exceeds array bounds. Index must not exceed 1.
Error in plotter (line 18)
u(j)=-Interval(4,i);
CODE:
function plotter( Interval,k,b )
%plots the various values of solutions u1(t) and u2(t) versus time
arrsize=18000;
x=zeros(1,arrsize-1);
x1=zeros(1,arrsize-1);
u=zeros(1,arrsize-1);
%%creating x as linear x-axis
for i=1:arrsize-1
x(i)=i*b/arrsize;
end
for j=1:arrsize-1
for i=1:k
if((x(j)>=(((i-1)*b/k)))&&(x(j)<((i)*b/k)))
x1(j)=Interval(1,i);
u(j)=-Interval(4,i);
%%%%%%%%%%%%%%%%%%%%%%%%
%% because u(t)=-p2(t) %%
%%%%%%%%%%%%%%%%%%%%%%%
end
end
end
figure(1);
plot(x,max(x1,0),'DisplayName','x1 (first state variable)'); hold on;
plot(x,max(u,0),'DisplayName','u (control variable)');
axis([0 b 0 6.2]); % This give the range on x-axis and y-axis in the graph
legend('show');
set(gca,'FontSize',12);
end
0 Kommentare
Akzeptierte Antwort
KSSV
am 26 Feb. 2022
Your inputs to the function are not correct. The function:
plotter( Interval,k,b )
Interval should be an array/ vector.
Example:
Interval = rand(1,8) ; % should be an vector
k = 1;
b = 1;
plotter( Interval,k,b )
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spline Postprocessing 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!