Matlab:如何创建函数?在本例中,我的脚本是一个函数
我想在Matlab和c->之间创建一个接口,所以我必须将我的M文件转换成DLL库 我在命令窗口中输入deploytool。 当窗口打开时,我选择库编译器。 对于类型I,请选择.NET程序集 现在我的问题来了: 添加导出函数->我必须选择我的Matlab函数。 但是你可以看到我的m文件是一个脚本而不是一个函数。但我需要一个函数。。 如何将其从脚本转换为函数?我是说密码。语法如何?我从未使用过函数。 该函数应该需要一个输入参数。输出应该是图表。但这是实现附件Matlab:如何创建函数?在本例中,我的脚本是一个函数,matlab,Matlab,我想在Matlab和c->之间创建一个接口,所以我必须将我的M文件转换成DLL库 我在命令窗口中输入deploytool。 当窗口打开时,我选择库编译器。 对于类型I,请选择.NET程序集 现在我的问题来了: 添加导出函数->我必须选择我的Matlab函数。 但是你可以看到我的m文件是一个脚本而不是一个函数。但我需要一个函数。。 如何将其从脚本转换为函数?我是说密码。语法如何?我从未使用过函数。 该函数应该需要一个输入参数。输出应该是图表。但这是实现附件 diagramoptions = [];
diagramoptions = [];
diagramlimits = [];
inputdata = [];
diagramoptions2 = [];
diagramlimits2 = [];
inputdata2 = [];
diagramoptions3 = [];
diagramlimits3 = [];
inputdata3 = [];
wholecontent = fileread('aaaa.txt')
sections = regexp(wholecontent, '\*+([^*]+)\*+([^*]+)', 'tokens')
counter=0; %Sollte mir die Anzahl der Diagramme zurückgeben
for section = sections
switch(strtrim(section{1}{1}))
case 'Diagram Options' %Diagram Options -> siehe meine Gliederung im .txt file
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')%\n -> new line; \r carriage return
diagramoptions = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
counter=counter+1;
case 'Diagram Limits'
header = strsplit(regexp(section{1}{2}, '[^\n\r]*', 'match', 'once'))
content = textscan(section{1}{2}, repmat('%f', 1, numel(header)), 'HeaderLines', 2)
diagramlimits = table(content{:}, 'VariableNames', header)
case 'Input Data'
inputdata = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
%output_inputdata(1) = inputdata;
case 'Cutoff Lines1'
cuttofflines1 = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))%Cutofflines
case 'Diagram Options2' %Diagram Options -> siehe meine Gliederung im .txt file
keyvalues2 = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')%\n -> new line; \r carriage return
diagramoptions2 = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
case 'Diagram Limits2'
header2 = strsplit(regexp(section{1}{2}, '[^\n\r]*', 'match', 'once'))
content2 = textscan(section{1}{2}, repmat('%f', 1, numel(header2)), 'HeaderLines', 2)
diagramlimits2 = table(content2{:}, 'VariableNames', header2)
case 'Input Data2'
inputdata2 = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
%output_inputdata(2) = inputdata;
case 'Diagram Options3' %Diagram Options -> siehe meine Gliederung im .txt file
keyvalues3 = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')%\n -> new line; \r carriage return
diagramoptions3 = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
case 'Diagram Limits3'
header3 = strsplit(regexp(section{1}{2}, '[^\n\r]*', 'match', 'once'))
content3 = textscan(section{1}{2}, repmat('%f', 1, numel(header3)), 'HeaderLines', 2)
diagramlimits3 = table(content3{:}, 'VariableNames', header3)
case 'Input Data3'
inputdata3 = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))%dh: ich habe 1 Headerline zur besseren übersicht
case 'Input Data4'
inputdata = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
%output_inputdata(1) = inputdata;
otherwise
warning('Unknown section: %s', section{1}{1})
end
end
我的输入文本:
*******************Cutoff Lines1****************
-100 100
-200 200
******************* Diagram Options****************
rainflow=1
woehler=0
number_of_plots=4
color=red
linewidth=12
header=Number of cycles
xlabel= RPM
ylabel= Amount
cutoffvalue=53
equivcycles=1e6
equivstress=40
wsectionslope=3 3 3
ordinatelogarithmic=false
wsectionstart=1000 5000000 3000000
wsectionsend=5000000 1000000000 30000000
wsectionlinestyle=cont dashed cont
wsectionstartstress=58.02349610358 58.02349610358 130
******************* Diagram Limits****************
xmin xmax ymin ymax zmin zmax
1 111 1111111 1 1 11
*******************Input Data****************
-220.8 228 50045
-222 201.6 50045
-219.6 19.2 200176
-168 19.2 100088
******************* Diagram Options2****************
number_of_plots=4
wsectionstart=1000 5000000 3000000
******************* Diagram Limits2****************
xmin xmax ymin ymax zmin zmax
0 0 100000 1 1 1100000
*******************Input Data2****************
106.62 1
106.62 50045
18.5181 12260785
******************* Diagram Options3****************
number_of_plots=23655888855665
******************* Diagram Limits3****************
xmin xmax ymin ymax zmin zmax
0 0 100000 1 1 1100000
*******************Input Data4****************
-220.8 228 50045
-222 201.6 50045
-220.2 198 200176
你试过把它放在顶部吗?你可以在没有输入和/或输出的情况下使用matlab函数。只需将函数放在顶部,使其名称与文件名匹配。好的,我将尝试。但是如果我有一个函数,在我的例子中有一个输入,一个.txt文件,在我的例子中有一个输出,只是一个绘图窗口,那么语法会是什么样子呢。或者这不是一个真实的输出?我绝望了。但无论如何,谢谢