繁体   English   中英

如何在MATLAB GUI中使用for循环进行Simulink文件的并行仿真,或者有另一种方法可以做到?

[英]How can I do side-by-side simulation of Simulink files by using for-loop in MATLAB GUI or is there another way to do it?

我想问一下如何通过MATLAB GUI中的for循环使以下代码用于Simulink文件的并行仿真,这些文件存储在“ PATH”中,或者您是否知道替代方法。 在我开始运行代码后,尽管没有错误消息出现,但是没有任何反应。 我也希望你们中的一些人能解决我的问题。

提前非常感谢您!

function nightly_simulation_Callback(hObject, eventdata, handles)
% hObject    handle to nightly_simulation (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
PATH = 'C:\Users\xxx\Documents\Saved_Models';
files=dir([PATH,'*.slx']);
fileNames={files.name}; 
fileNames=sort(fileNames);
nFiles=numel(fileNames); 
selection = questdlg('Sure to start?',...
    'Confirmation',...
    'Yes','No','Yes');
switch selection
    case 'Yes'
        for i=1:nFiles  
            x = [PATH,fileNames{i}];
            open_system(x);
            sim(x);
        end
    case 'No'
        return
end

更换

x = [PATH,fileNames{i}];

x = fullfile(PATH, fileNames{i}); 

因为否则文件名中缺少'\\'

我这样更改了代码:

function nightly_simulation_Callback(hObject, eventdata, handles)
% hObject    handle to nightly_simulation (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
PATH = 'C:\Users\xxx\Documents\Saved_Models';
files = dir( fullfile(PATH,'*.slx') );   %# list all *.slx files
fileNames = {files.name}';
fileNames=sort(fileNames);
nFiles=numel(fileNames); 
selection = questdlg('Sure to start?',...
    'Confirmation',...
    'Yes','No','Yes');
switch selection
    case 'Yes'
        for i=1:nFiles  
       x = fullfile(PATH, fileNames{i}); 
       open_system(x);
       sim(x);
end
    case 'No'
        return
end

也有效。 谢谢你的建议!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM