Question
Why does the following don't work or what needs to be added? % --- Executes on button press in pbCalculate. function pbCalculate_Callback(hObject, eventdata, handles) x=handles.VarXStart:handles.VarXRes:handles.VarXEnd; fh=@(x) handles.Function; plot(x,fh(x)) "handles.Function" contains for example "x.^2" or "sin(x)" (it's a string). Typed into a textfield in the GUI by a user. I've googled now a whole day long and couldn't find anything that worked.
Expert Answer
Kshitij Singh
PhD Expert
Answered Aug 20, 2026
Try this:
str='x.^2'; f=inline(str); x=0:0.1:4; plot(x,f(x))
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related plot Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →