2

What I am trying to do is that when I put into "Edit text" (called: funkcia_edit) some function it will draw me graf to that function. Here is picture what I am trying to do, as you can see I have declared variables X and Y where Y is standing for funkcia_edit = x.^2 and then I want to plot(x,y). Can any one help me how to make it work?

Thanks

enter image description here

Mario LIPCIK
  • 457
  • 2
  • 9
  • 24

2 Answers2

3

I think what you're missing is the eval function in Matlab. If I'm not mistaken what you want to do is

y = eval(get(hObject,'String'));

Observe that while this is probably the easiest way of programming this functinality in MATLAB it is not necessary the safest. A user could write system('rm -rf *') and your program will evaluate that.

Eitan T
  • 32,660
  • 14
  • 72
  • 109
carlosdc
  • 12,022
  • 4
  • 45
  • 62
0

You can also use ezplot:

   ezplot(get(hObject,'String'));
Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104