I have a question about GUI with Code

조회 수: 2 (최근 30일)
Alan
Alan 2024년 10월 19일
댓글: Walter Roberson 2024년 10월 21일
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'));

답변 (1개)

Taylor
Taylor 2024년 10월 21일
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
Walter Roberson
Walter Roberson 2024년 10월 21일
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.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by