.exe with inputs

조회 수: 16 (최근 30일)
Sergio Quesada
Sergio Quesada 2018년 7월 20일
답변: Image Analyst 2018년 7월 20일
Good afternoon,
I am new in MatLab, so I am no familiarized yet with making functions and programs. I have designed these lines to obtain some information from my data file called 'TR007-3_1FL.txt':
fID=fopen('TR007-3_1FL.txt','r');
A=0.017; Po=100;
formatSpec='%f %f'; sizeSpec=[2,Inf]; datos=fscanf(fID,formatSpec,sizeSpec); close('all');
vexp=datos(1,:);iexp=-1.*datos(2,:);ivexp=iexp.*vexp;jexp=iexp./A;jvexp=jexp.*vexp;
Voc=interp1(iexp,vexp,0)
Isc=interp1(vexp,iexp,0)
, and now I want to make it an .exe that can be executed on a PC without installing MatLab. I think I have the Compiler Toolbox, but I do not know how to make the program a function that asks me to enter different files names and 'A' and 'Po' parameters for each different file to analyze. Could you please give me any help?
Thank you so much !

채택된 답변

Fangjun Jiang
Fangjun Jiang 2018년 7월 20일
use uigetfile() to allow user to pick a file.
use input() to allow user to input a value.
After you test out your new program, run "deploytool" to compile your program to a stand-alone application, assume you have all the Toolbox needed.
  댓글 수: 2
Sergio Quesada
Sergio Quesada 2018년 7월 20일
편집: Sergio Quesada 2018년 7월 20일
Thanks Fangjun Jiang !! The .exe runs properly!!
Just a thing. When asking for parameter, after introducing a value, e.g. "2", it gives an error:
"2" is not recognized as an internal or external command, operable program or batch file
but then, writing it down again and ENTER, gives no problem ! Why?? It is more fancy if the first error does not appear...
Thanks again
Image Analyst
Image Analyst 2018년 7월 20일
Give the code and the entire error message - ALL the red text or error text in the console window.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 7월 20일
Simply call uigetfile() to ask the user for a file:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = pwd; % or 'C:\wherever';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
To ask the user for an integer number, do this:
% Ask user for one integer number.
defaultValue = 45;
titleBar = 'Enter an integer value';
userPrompt = 'Enter the integer';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
integerValue = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(integerValue)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
integerValue = defaultValue;
message = sprintf('I said it had to be an integer.\nTry replacing the user.\nI will use %d and continue.', integerValue);
uiwait(warndlg(message));
end
To ask the user for a couple of floating point numbers, do this:
% Ask user for two floating point numbers.
defaultValue = {'45.67', '78.91'}; % Whatever you want.
titleBar = 'Enter a value';
userPrompt = {'Enter floating point number 1 : ', 'Enter floating point number 2: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
usersValue2 = str2double(caUserInput{2})
% Check usersValue1 for validity.
if isnan(usersValue1)
% 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 usersValue1.
usersValue1 = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue1);
uiwait(warndlg(message));
end
% Do the same for usersValue2
% Check usersValue2 for validity.
if isnan(usersValue2)
% 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 usersValue2.
usersValue2 = str2double(defaultValue{2});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue2);
uiwait(warndlg(message));
end
Adapt as needed.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by