I have a question about GUI with Code

1 view (last 30 days)
Alan
Alan on 19 Oct 2024
Commented: Walter Roberson on 21 Oct 2024
Hello, I have a code that I did not make, but I took it from a book, I want to execute the code for a thesis, but the code is written for a GUI interface, my question is, if the code that I have can be execute and have the GUI interface appear without me making the interface, how do I do it? And if it can't be done... should I make the interface? I share the first lines of the code that I took from the book.
% --- Executes on button press in ce.
function ce_Callback(hObject, eventdata, handles)
clc; cla(handles.grafica);
nro=str2double(get(handles.nro,'string')); V=str2double(get(handles.V,'string'));
nct=str2double(get(handles.nct,'string')); ncf=str2double(get(handles.ncf,'string'));
ccond=str2double(get(handles.ccond,'string')); Y=str2double(get(handles.Y,'string'));
h=str2double(get(handles.h,'string')); n=str2double(get(handles.n,'string'));

Answers (1)

Taylor
Taylor on 21 Oct 2024
You can definitely edit this code to function without the GUI. You won't need hObject or eventdata; these are variables specific to the GUI. But the structure handles contains the information that is actually used in the function block. Generally, the code is just taking fields from handles that contain strings, converting them to double values with str2double, and storing the new double values in their own variables outside of the original structure.
  1 Comment
Walter Roberson
Walter Roberson on 21 Oct 2024
the code is just taking fields from handles that contain strings
It would be a bit of a nuisance to create a class that contains a property named string in order for the get() of 'string' to work -- but it is certainly do-able. Overall it might be easier to replace
get(handles.nro,'string')
with
handles.nro.string
and make corresponding changes to the setting code.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!