Plotting values by defining a function plotter

조회 수: 1 (최근 30일)
Kunal Jain
Kunal Jain 2022년 2월 26일
댓글: Kunal Jain 2022년 2월 26일
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

채택된 답변

KSSV
KSSV 2022년 2월 26일
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 )
  댓글 수: 1
Kunal Jain
Kunal Jain 2022년 2월 26일
Thanks for answering
I got it that Interval should be an array/vector.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by