필터 지우기
필터 지우기

inputdlg if ok pressed load this code

조회 수: 4 (최근 30일)
Khalala Mamouri
Khalala Mamouri 2020년 8월 30일
댓글: Khalala Mamouri 2020년 8월 30일
Hi all,
i am developping an app in APP designer and this is a part of my code.
i am looking for a way to : when the user clicks on "OK", the user inputs get stored to a file, else if the user selects cancel then it cancels.
QUESTION : How to use "if " to tell matlab that the user clicked on OK !
thanks
prompt = {'Cell Voltage (V)','Cell Capacity (Ah)'};
dlgtitle = 'Add New Battery';
dims = [1 100; 1 100];
definput = {'Cell Nominal Voltage','Nominal Capacity'};
answer = inputdlg(prompt,dlgtitle,dims,definput,'on');
if ( user clicks on "OK" then this code is used)
V_Cell_Nom = str2double(answer{1});
C_elb = str2double(answer{2});
fileID = fopen('exp.m','a+');
fprintf(fileID,'%s %d \n','V_Cell_Nom = ',V_Cell_Nom);
fprintf(fileID,'%s %d \n','C_elb = ',C_elb);
fclose(fileID);
elseif ( user clicks on "cancel", then stop the program)
return;
end

채택된 답변

Voss
Voss 2020년 8월 30일
if isempty(answer) % user clicked 'Cancel' or closed the dialog box without clicking 'OK'
return
end
% user clicked 'OK'
% do stuff
  댓글 수: 1
Khalala Mamouri
Khalala Mamouri 2020년 8월 30일
it was that simple !!!!!!!!!!!!!
thanks mate

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by