使用MATLAB命令保存特定文件 [英] save specific files with MATLAB commands

查看:122
本文介绍了使用MATLAB命令保存特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将模型保存为最旧的MATLAB版本,如下所示 我在寻找每个文件夹和子文件夹以找到任何.mdl或.slx并将其保存为2007b版本

I'm trying to save models in oldest MATLAB versions as below I look for each folder and subfolder to find any .mdl or .slx to save it as 2007b version

我的问题是:

  1. 如果我只是想寻找一个扩展名,而我想知道的话,它就可以工作 在每个.mdl和.slx上执行此操作.
  2. save_system花费太多 时间
  1. it works if I just look for one extension whereas I'm wondering to do that on each .mdl and.slx .
  2. the save_system takes too much time

您知道我如何获得所有.mdl和.slx,是否有一种优化的保存方式?

Do you know how could I get all .mdl and .slx and is there an optimized way to save ?

谢谢

rootPath = fullfile('M:\script\ytop','tables');
files = dir(rootPath );

for ii = 3:numel(files)

x = fullfile(rootPath ,files(ii).name);
cd(x);
mdl = { dir('*.mdl'),dir('*.slx')};  % here it works if only I set dir('*.mdl')
for jj = 1:numel(mdl)
    load_system(mdl(jj).name);
    save_system(mdl(jj).name,mdl(jj).name, 'SaveAsVersion','R2007b');
end   

end

推荐答案

%here you used {} which created a cell array of two structs. cat creates a single struct which.
mdl=cat(1,dir('*.mdl'),dir('*.slx')); 
for jj = 1:numel(mdl)
    [~,sysname,~]=fileparts(mdl(jj).name);
    load_system(mdl(jj).name);
    %use only sysname without extension. R2007b is mdl only. You can't store files for R2007b in slx format
    save_system(sysname,sysname, 'SaveAsVersion','R2007b');
    %close system to free memory.
    close_system(sysname);
end   

仅应用必需的修复程序,您的代码会有一种奇怪的行为.对于mdls,该文件将替换为原始文件,对于slx,将在原始文件旁边创建一个mdl.您可能要在加载后添加delete(mdl(jj).name).

Applying only the required fixes your code has one odd behaviour. For mdls the file is replaced with the original one, for slx a mdl is created next to the original one. You may want to add a delete(mdl(jj).name) after loading.

这篇关于使用MATLAB命令保存特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆