How to show symbolic equation answer in GUI controllers like static text

Hello,
I'm trying to create application to solve curl of functions that users input in text box and then plot however I cannot achieve to get the static text lable to show the answer. I tried (for simplicity) to assign the equation myself in the editor but it did not work, however when solving something that does not contains symbols (x, y) it works (like log(10)). In troubleshooting I tried to solve diff like that:
syms x
f = sin(5*x)
set(handles.answerTxt, 'String', diff(f));
it didn't work
however when set the answerTxt to
set(handles.answerTxt, 'String', log(10));
it works, so obviously the problem is all about how to pass symbolic equation answer in GUI components.
Thanks

 Accepted Answer

set(handles.answerTxt, 'String', char(diff(f)));

8 Comments

Tried before but it did not work :) Thanks
First, I'd like to appreciate your help and concern :) Thank you. I'm really stuck in getting this to work. All I want is to pass the results of any symbolic function like integration, differentiation, curl, divergence, .... to a static box
what you suggested returns nothing but the same error
my code as u suggested
syms f;
f=x^2;
set(handles.txtAns, 'String', char(diff(f)));
error
Undefined function or variable 'x'.
Error in test>pushbutton1_Callback (line 82)
f=x^2;
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in test (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)test('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
WOW !!!!!!!!!!!! Brilliant :D it works, the static text now shows 2*X thank you very very much :) thank you :) I'm speechless :D ... I will try now using the curl function and let's see what I will get
well, the curl function works great and the text shows matrix[] and the answer in between the brackets (will have to look for some tweaks in showing the results in a pretty way like a real matrix *multiplelines)
I'm trying to advance in my application and let the users input the 3 vector components that the curl will be calculated from. Input forms are xEquation, yEquation, zEquation,
syms x y z;
xInput=get(handles.xEquation, 'String');
yInput=get(handles.yEquation, 'String');
zInput=get(handles.zEquation, 'String');
set(handles.txtAns, 'String', char(curl([xInput, yInput, zInput], [x, y, z])));
For some reason it didn't work and the error says
Error using sym/curl (line 29)
Input vectors must be three-dimensional.
Error in test>pushbutton1_Callback (line 85)
set(handles.txtAns, 'String', char(curl([xInput, yInput, zInput], [x, y, z])));
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in test (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)test('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
this error "input vector must be three-dimensional doesn't make any sense, as in the curl function I define the 3 dimensions which are variable containing the value the users input in the text box.
[xInput, yInput, zInput] when those are all strings, is going to result in a single concatenated string. You need to put sym() around your get()
You are a genius :) works like charm :) and many thanks for clarification why it didn't work, really helpful. I'm now working on plotting the answer of the curl :) reading about plot3 and quiver3 should help me out, right ?

Sign in to comment.

More Answers (1)

6 Comments

Sounds cool however I still can't get it. Syntax says that
guidata(object_handle,data);
data = guidata(object_handle);
so now I have to write my application like this (push button callback)
syms x;
f = sin(5*x);
guidata(handles.answerTxt,data);
data = guidata(handles.answerTxt, 'String', diff(f));
I did give it a try but nothing happened. Could you please give me more clarification ?
To update handles
syms x;
f = sin(5*x);
handles.f=f
guidata(hObject,handles);
To get f use
f=handles.f
Dear Azzi, I'm still noob, I can't get the clue of what you're trying to say. Sorry
Post the function where you have problems
Azzi, Mohamed is trying to get a text label to contain the character representation of the differentiation of the symbolic expression "f", not trying to store the symbolic expression itself.
I did try everything with guidata, and I did read about it in the help but nothing helped me through what I'm trying to achieve

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!