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 Center および File ExchangeSpline Postprocessing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by