Is it possible to pass parameters an standalone .exe (script -> deploytool -> standalone exe -> using this exe with a txt-File as an Input)

3 Ansichten (letzte 30 Tage)
I have a matlab Code (Script). I use deploytool to create a standalone .exe Is it possible to pass this exe parameters? Has the code to be a function therfore? At the moment my input file is a .txt File
r_inputdataSigmaX=[;];
r_inputdataSigmaY=[;];
r_inputdataTau=[;];
w_inputdataTau=[;];
w_inputdataSigmaY=[;];
w_inputdataSigmaX=[;];
cuttofflinesSigmaX=[;];
cuttofflinesSigmaY=[;];
cuttofflinesTau=[;];
r_inputdata_logic=zeros(1,3);
w_inputdata_logic=zeros(1,3);%[0;0;0]; %zeros(m,n)
inputdata_cuttofflines_logic=zeros(1,3);%[0;0;0];
default_value_z=1e8; %hier setze defaultmässig die z Komponente/Wert der Cutofflinien
row1=0;
row2=0;
row3=0;
index_counter=1;
t=0;
set(groot,'DefaultFigureColormap',jet)
%Einlese Prozedere
%wholecontent = fileread(Input_File);
wholecontent = fileread('Matlab_Export.txt')
%wholecontent = fileread(Input_File);
sections = regexp(wholecontent, '\*+([^*]+)\*+([^*]+)', 'tokens')
for section = sections
switch(strtrim(section{1}{1}))
case 'Plot Page Options and Settings'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
plotpageSettings = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Die Diagram Options gelten jeweils für rainflow und woehler
case 'Diagram Options SigmaX'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
diagramoptionsSigmaX = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
case 'Diagram Options SigmaY'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
diagramoptionsSigmaY = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
case 'Diagram Options Tau'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
diagramoptionsTau = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'Woehler Lines SigmaX'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
w_diagramoptionsSigmaX = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
w_inputdata_logic(1,1) = 1;
case 'Woehler Lines SigmaY'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
w_diagramoptionsSigmaY = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
w_inputdata_logic(1,2) = 1;
case 'Woehler Lines Tau'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
w_diagramoptionsTau = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
w_inputdata_logic(1,3) = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'Rainflow Options SigmaX'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
r_diagramoptionsSigmaX = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
case 'Rainflow Options SigmaY'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
r_diagramoptionsSigmaY = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
case 'Rainflow Options Tau'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
r_diagramoptionsTau = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'Rainflow Cutofflines SigmaX'
cuttofflinesSigmaX = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
inputdata_cuttofflines_logic(1,1) = 1;
case 'Rainflow Cutofflines SigmaY'
cuttofflinesSigmaY = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
inputdata_cuttofflines_logic(1,2) = 1;
case 'Rainflow Cutofflines Tau'
cuttofflinesTau = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
inputdata_cuttofflines_logic(1,3) = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'StressSpectrum Data SigmaX'
w_inputdataSigmaX = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
case 'StressSpectrum Data SigmaY'
w_inputdataSigmaY = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
case 'StressSpectrum Data Tau'
w_inputdataTau = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'Rainflow Data SigmaX'
r_inputdataSigmaX = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
r_inputdata_logic(1,1) = 1;
case 'Rainflow Data SigmaY'
r_inputdataSigmaY = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
r_inputdata_logic(1,2) = 1;
case 'Rainflow Data Tau'
r_inputdataTau = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
r_inputdata_logic(1,3) = 1;
otherwise
warning('Unknown section ERROR: %s', section{1}{1})
end
end

Akzeptierte Antwort

Steven Lord
Steven Lord am 28 Apr. 2017
If you want to pass inputs to a program in MATLAB, that program must be either a function or a class (with a constructor that accepts input arguments.) Scripts don't take input arguments.
There's a section in the documentation for MATLAB Compiler that discusses how to pass input arguments into standalone applications.
Probably the most common problem I see when people try to pass inputs into their standalone applications is called out in that section of the documentation:
"The input arguments you pass to your executable from a system prompt will be received as character vector input. Thus, if you expect the data in a different format (for example, double), you must first convert the character vector input to the required format in your MATLAB code. For example, you can use str2num to convert the character vector input to numerical data."
If you want to read data from a file into your application, you may be able to adapt some of the techniques described on this page that load data to work with other file I/O functions. Specifically note the code in the example that locates the directory containing the files.
  2 Kommentare
Philipp Mueller
Philipp Mueller am 28 Apr. 2017
Hello @Steven Lord. Thank you for your response. Ok i made a function:
function [ result ] = rainflow_spectrum(Input_File)
wholecontent = fileread(Input_File);
So my question now: How can i give my function (standalone .exe) an input File (.txt_file) in my DOS Command Window? Thank you
Steven Lord
Steven Lord am 28 Apr. 2017
See the "Pass File Names, Numbers or Letters, Matrices, and MATLAB Variables" section of the first documentation page to which I linked in my answer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Vibration Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by