Problem on code while plotting a graph

I am plotting a graph, with the line:
figure;
hold on ;
.....
title('function');
.....
hold off;
But I ended up with an error of "Index exceeds array bounds." on the title line. How can I solve this?

4 件のコメント

Angus Wong
Angus Wong 2018 年 6 月 19 日
編集済み: Angus Wong 2018 年 6 月 19 日
This is my code:
figure;
hold on;
fplot(y,[xmin xmax]);
ylim([ymin ymax]);
title('function');
xlabel('x');
ylabel('f(x)');
hold off;
The error message is:
Index exceeds array bounds.
Error in lagrangianinterpolation2 (line 113)
title('function');
Paolo
Paolo 2018 年 6 月 19 日
figure;
hold on ;
title('function');
hold off;
Works fine on my machine with 2017b, what Matlab version are you using?
Angus Wong
Angus Wong 2018 年 6 月 19 日
編集済み: Angus Wong 2018 年 6 月 19 日
2018a
Paolo
Paolo 2018 年 6 月 19 日
編集済み: Paolo 2018 年 6 月 19 日
Star Strider is right, the error is probably not related to the title command.

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2018 年 6 月 19 日
編集済み: Star Strider 2018 年 6 月 19 日

0 投票

The actual error is most likely in the line just above your title call.
Check it to be certain it is entered correctly.
EDIT (16:10 UCT)
What is your ‘y’ function?
Note that in your code, and using fplot, ‘y’ must be a function of one variable.

4 件のコメント

Angus Wong
Angus Wong 2018 年 6 月 19 日
I defined y as:
y=@(x)(p1*x+p0);
Written on the line just before the line 'figure;'
Angus Wong
Angus Wong 2018 年 6 月 19 日
編集済み: Angus Wong 2018 年 6 月 19 日
The codes are:
t1=A(2,1)/(A(1,1)-A(1,2));
t2=A(2,2)/(A(1,2)-A(1,1));
p1=t1+t2;
p0=-t1*A(1,2)-t2*A(1,1);
if p1==inf || p1==-inf || isnan(p1)==1
uiwait(msgbox('Error. Rerun the program.','Error!','error'));
p1=0;
p0=0;
yf1=0;
yf2=0;
yf3=0;
return;
end
if abs(p1)<10^-10
p1=0;
end
if abs(p0)<10^-10
p0=0;
end
fprintf(1,'The equation is f(x) = %g x + %g . \n',p1,p0);
disp(' ');
xmin=min(A(1,:))-1;
xmax=max(A(1,:))+1;
ymin=min(A(2,:))-2;
ymax=max(A(2,:))+2;
y=@(x)(p1*x+p0);
figure;
.....
Where A is a 2 by 2 matrix full of numbers.
Angus Wong
Angus Wong 2018 年 6 月 19 日
Thanks guys, I know where I made the mistake.
Star Strider
Star Strider 2018 年 6 月 19 日
As always, my (our) pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

製品

リリース

R2018a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by