目录
1、环境搭建
打开matlab之后,在命令行输入mcr。

由于环境没有配置,所以会报错的,找不到Runtime。
根据命令提示,在命令行输入compiler.runtime.download

由于matlab自身下载非常慢所以,要去另一个地方下载(网页),那么此时的操作为在命令行窗口按下CTRL+C,没看错就是这个组合键,这不是复制而是matlab中的命令停止,输入之后会得到以下输出:

将上图中的网站复制并粘贴到网页上即可下载,每个matlab版本对应不同的Runtime版本,这个方法是最简单的下载方法,不必去matlab官网上寻找。

将刚下载的压缩包压缩,随便压缩到一个地方,建议压缩到英文路径。

压缩之后进行安装,双击setup,然后进行漫长的等待,这一步就做完了,记得将setup安装的文件放在非matlab文件夹,装完之后是这样子。
![]()
打开我的电脑中的系统属性

点击高级系统

再点击环境变量

点击path之后点编辑

添加这几个环境变量

此时恭喜你环境已经搭建好了。
2、web搭建
在matlab文件夹中顺着找到下述文件夹,应该没有uu把我电脑上的文件夹复制到自己电脑上然后发现找不到,最后再回来说不行吧。
D:\software_code\matlab\toolbox\compiler\deploy\win64\MATLABWebAppServerSetup\offline
解压这个路径下的压缩包,随便路径
![]()
解压之后运行,管理员运行!管理员运行!

选第一个选项注册一下,这里我已经注册过了。

点击 RUN,就开始运行了,Home Page是你的网页,AppFolder是App所在的文件夹,在这里放上App的.ctf文件就可以运行了。

![]()
打开Home Page后是这个画面,同一个局域网中的用户可以访问此App,点击即可使用。

2.1 内网分享-防火墙开启
1、找到控制面板,打开防火墙。 
2、点击左边启动或关闭防火墙,将所有防火墙都打开。
3、点击左边“高级设置”

4、点击“入站规则”-“新建规则”-“端口”-“TCP”-“特定本地端口”-“允许连接”

3、APP.ctf文件生成
那么问题来了APP的.ctf文件怎么生成呢?
打开matlab 点击App,找到Web App Compiler,如果找不到就要自己下载,去获取更多App中搜索即可,如果你是盗版的,请重装matlab,重装的时候选择这个matlab compiler。


点击Web App Compiler

选择App,点击对号,package。
4、web技巧
4.1 web导入与下载excel
% Button pushed function: UploadButton
function UploadButtonPushed(app, event)
[file, path] = uigetfile({'*.csv*'}, 'File Selector', 'MultiSelect', 'on');
if isequal(file,0)
disp('Canceled')
else
% Read input file
inpuFilePath = fullfile(path,file);
tbl = readtable(inpuFilePath);
% Do some calculation
app.resultTbl = table;
app.resultTbl.col1 = tbl.col1 + tbl.col2 + tbl.col3;
end
end
% Button pushed function: DownloadButton
function DownloadButtonPushed(app, event)
[file,path] = uiputfile('results.xlsx');
resultFilePath = fullfile(path,file);
writetable(app.resultTbl, resultFilePath)
end
app.resultTbl = table(t',id',iq',ia',ib',ic',Pa_SiC',Pb_SiC',Pc_SiC',Ta_SiC,Tb_SiC,Tc_SiC,'VariableNames',{'t','id','iq','ia','ib','ic','Pa_SiC','Pb_SiC','Pc_SiC','Ta_SiC','Tb_SiC','Tc_SiC'});
4.2 输出动态log
使用时需要先建立一个messageTextArea。
%%% 先建立私有属性 cellArrayText
%%% 初始化
app.cellArrayText{1} = sprintf('%s\n', '***此处输出信息提示***'); % 赋初值
app.messageTextArea.Value=app.cellArrayText{1}; % 文本区域中的初始显示信息
%%% 建立输出函数
function outPut(app,str)
string = sprintf('%s\n', str); % 将数据格式化为字符串或字符向量
app.cellArrayText=horzcat(app.cellArrayText,string); % 水平串联数组
app.messageTextArea.Value = app.cellArrayText; % 给TextArea赋值
end
%%% 调用
outPut(app,['时间:',datestr(now,'HH:MM:SS'),' 错误信息:','热阻配置错误']) ;
scroll(app.messageTextArea, 'bottom');
4.3 搜索功能
%% 1.先建立一个原始信息文本switchname
%% 2.建立搜索文本switchname_2,加入搜索框searchbox与确定按钮
%% 3.编写函数,两个文本要确认要最终赋值一个变量,系统最后读取一个file,关键在于switchnameValueChanged函数
keyword = app.searchbox.Value;
matchingFiles{1}='';
for i = 2:length(app.switchname.Items)
if contains(app.switchname.Items{i}, keyword, 'IgnoreCase', true)
matchingFiles{end+1} = app.switchname.Items{i};
end
end
matchingFiles = matchingFiles(~cellfun('isempty', matchingFiles));
app.switchname_2.Items=matchingFiles;
switchname_2ValueChanged(app);
app.switchname.Value = app.switchname.Items;
function switchnameValueChanged(app, event)
app.filename = [app.location '\' app.switchname.Value];
loss = readtable(app.filename,'Sheet','loss');
thermal = readtable(app.filename,'Sheet','thermal');
app.remark.loss = table2array(loss(:,1));
app.remark.loss = string(app.remark.loss);
app.remark.loss = app.remark.loss(app.remark.loss~='');
app.remark.thermal = table2array(thermal(:,1));
app.remark.thermal = string(app.remark.thermal);
app.remark.thermal = app.remark.thermal(app.remark.thermal~='');
app.TextArea_database.Value = [app.remark.loss;'';app.remark.thermal];
end
4.4 进度条
%进度条
scan_indx = obj.idx.saveNo;
totalnum = size(obj.idx.all,1);
Con = (mod(scan_indx,ceil(0.1*totalnum)) == 0||scan_indx<(0.05*totalnum)||scan_indx>(0.95*totalnum));
if(Con)
app.Progress.Value=['Ongoing :',num2str(floor(scan_indx/totalnum*100)),'%']; %输出文字百分比;round函数四舍五入取整
drawnow;
end
本文详细介绍了如何在MATLAB环境中进行环境配置,包括Runtime的下载与安装,以及Web应用的搭建过程,涉及APP.ctf文件的生成和Web技巧如导入Excel和动态日志输出。
1704

被折叠的 条评论
为什么被折叠?



