Index in position 1 is invalid. Array indices must be positive integers or logical values.

4 ビュー (過去 30 日間)
Nicholas Isales
Nicholas Isales 2019 年 10 月 8 日
コメント済み: Walter Roberson 2019 年 10 月 11 日
I'm trying to make a surface plot but i get the error message where F is a function of x and y but I dont understand what the error message I get means so any help appreciated. Code below error occurs at line 3
function [] = mySurfacePlotter( F,x,y,option)
[X,Y] = meshgrid(x,y);
Z = F(X,Y);
if option == 'surf'
surf(X,Y,Z)
title('Surface');
xlabel('x');
ylabel('y');
else if option == 'contour'
contour(X,Y,Z)
title('Contour');
xlabel('x');
ylabel('y');
end
end
end
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 10 月 8 日
Whatever you are passing in to the first parameter is not a function handle.

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

回答 (1 件)

Nishant Gupta
Nishant Gupta 2019 年 10 月 11 日
Like Walter said, the first parameter 'F' need to be a function handle, for eg.
F=@(x,y)(sin(x)+cos(y))
One more thing is, if you select the 'option' as 'contour', it will again give an error. The possible reason for that is the size of the array which you are using to compare is 4 because if you make the slight change as following
else if option == 'cont'
then it will work or you can simply use 'strcmp' function.

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by