Info

此问题已关闭。 请重新打开它进行编辑或回答。

How do I write programming for this formula in MATLAB GUI ?

2 次查看(过去 30 天)
Please help me :)

回答(1 个)

Image Analyst
Image Analyst 2016-11-17
Try this
% Ask user for two floating point numbers.
defaultValue = {'2', '5'};
titleBar = 'Enter a value';
userPrompt = {'Enter Nmin : ', 'Enter Nmax: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Convert to floating point from string.
Nmin = str2double(caUserInput{1})
Nmax = str2double(caUserInput{2})
% Check for a valid number.
if isnan(Nmin)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into Nmin.
Nmin = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', Nmin);
uiwait(warndlg(message));
end
% Do the same for usersValue2
if isnan(Nmax)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into Nmin.
Nmax = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', Nmin);
uiwait(warndlg(message));
end
% Do the same to get Pmax and Pmin......THEN................
totalRange = abs(Nmax - Nmin) * abs(Pmax - Pmin)
message = sprintf('Total Range = %f', totalRange);
uiwait(helpdlg(message));

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by