2017-07-06 53 views
0

我正在通過Matlab中的循環調用Simulink仿真。我能夠發送很多數字參數(例如集成商的初始條件),但是在我的「From File」塊中會出現錯誤。「From File」從Matlab中調用的Simulink塊.m文件循環中

我不太確定其他人是如何做到的,但是我在哪裏工作,我們通過一個採用結構輸入的自制函數發送它。結構的字段是變量名稱,字段的值是變量本身。例如:

pb = struct('preload',preload(pl_index),... 
      'displacement',preload_displacement(pl_index),... 
      'filename',fileList{m}); 

的「預加載」和「位移」變量計算罰款,但filename給出了一個錯誤:

filename.mat 

有誰知道如果你能傳遞變量的值filenamefileList{m})在'From File'塊中,如果是的話,如何去做。謝謝!

+0

filename用作字符串參數,不作爲變量進行計算。你需要做set_param('from_file_block','filename',fileList {m})才能工作。 – Navan

+0

是的,我同意,但是,我們在工作中使用的腳本我不確定這是否可能......雖然好點,謝謝。 @Navan –

回答

1

回答我自己的問題!

我使用Simulink「從工作區」塊而不是「從文件」。

f = load(fileList{m}); 
fnames = fieldnames(f); 
% The files were arranged weird, so I have one field inside the structures... and they all had different names. 
    switch fnames{1} 
     case 'first' 
      filedata = f.first; 
     case 'second' 
      filedata = f.second; 
     case 'third' 
      filedata = f.third; 
     case 'fourth' 
      filedata = f.fourth; 
    end 
    t = filedata(1,:); 
    u = filedata(2,:); 

loaded_file = timeseries(u,t); 

而我通過loaded_file我的功能。

相關問題