Quantcast
Channel: Graphing with GUI - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by il_raffa for Graphing with GUI

$
0
0

Notice that according to the inline function documentation this function will be removed in future release; you can use, instead, anonymous functions (see below).

The inline function require, as input a string of characters while the get function returns the text of the edit box as a cellarray, therefore you have to convert it using the char function.

Also, once you have generated the inline object, it is you function, so you have to use it directly.

Using inline

You have to change your code this way:

x=-10:0.1:10;% f=inline(get(handles.vdj,'string'))% y(x)=ff=inline(char(get(handles.vdj,'string')))y=f(x)axes(handles.axes)ph=plot(x,y)

Using an anonymous function

You can achieve the same result by using anonymous functions this way:

x=-10:0.1:10;% Get the function as stringf_str=char(get(handles.vdj,'string'))% add @(x) to the string you've gotf_str=['@(x) ' f_str ];% Create the anonymous functionfh = str2func(f_str)% Evaluate the anonymous functiony=fh(x)axes(handles.axes)ph=plot(x,y)

Edit

You can fix the problem with the setting of the line color and style this way:

  • modify the call to plot by adding the return value (it is the handle to the plot (see above: ph=plot(x,y))
  • chance the calls to set by replacing the call to plot with the handle of the plot itself (the ph variable as above)

So, to change the color and the line style, in your switch section:

set(ph,'color','r')set(ph,'linestyle','--')

Hope this helps,

Qapla'


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>