Function with handle.

15 次查看(过去 30 天)
Martin
Martin 2011-8-11
Hi. I need some help with this problem. Can not see what I'm doing wrong.
The function takes an array of plot handles input parameters. The user must enter an ID number on the new graph and enter a text string that is interpreted as a function of x. The graph is shown i the figure window with the number that coincides with the ID number of the new graph. The handle that is drawn is stored in the array passed as inparameter and feature retunera this array to the main menu.
The function mainMeny:
function mainMeny
plot_handles = [];
iterera = true;
while iterera
.
.
.
case 1
plot_handles = skapaPlot(plot_handles);
end
The function skapaplot:
function [plot_handles] = skapaPlot(plot_handles)
% id = input('Ange fönster: ');
[id]=getPlotHandle(plot_handles);
func = inputdlg('Mata in en funktion: ');
x = linspace(0,10,100);
y = eval(func{1});
figure(id);
handle = plot(x,y),grid
plot_handles(id) = handle;
end
Error from MATLAB:
??? Undefined function or method 'getPlotHandle' for input arguments of type 'double'.
Error in ==> skapaPlot at 3 [id]=getPlotHandle(plot_handles);
Error in ==> mainMeny at 22 plot_handles = skapaPlot(plot_handles);
I would be grateful if you could help me.

回答(2 个)

Daniel Shub
Daniel Shub 2011-8-11
It looks like getPlotHandle is not defined. What do you get with
which -all getPlotHandle
  1 个评论
Martin
Martin 2011-8-11
I changed to:
function [plot_handles] = skapaPlot(plot_handles)
% id = input('Ange fönster: ');
which -all getPlotHandle;
%[id]=getPlotHandle(plot_handles);
func = inputdlg('Mata in en funktion: ');
I now get the chance to write a function, but then.
'getPlotHandle' not found.
??? Undefined function or variable 'id'.
Error in ==> skapaPlot at 11
figure(id);
Error in ==> mainMeny at 22
plot_handles = skapaPlot(plot_handles);

请先登录,再进行评论。


Martin
Martin 2011-8-11
Ok, things start to happen ... inch by inch. :)
with this function:
function [plot_handles] = skapaPlot(plot_handles)
id = input('Ange fönster: ');
%[id]=getPlotHandle(plot_handles);
which -all getPlotHandle;
func = inputdlg('Mata in en funktion: ');
x = linspace(0,10,100);
y = eval(func{1});
figure(id);
handle = plot(x,y),grid
plot_handles(id) = handle;
end
I get this message from MATLAB:
??? Error: Unexpected MATLAB expression.
Error in ==> skapaPlot at 8 y = eval(func{1});
Error in ==> mainMeny at 22 plot_handles = skapaPlot(plot_handles);

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by