フィルターのクリア

Bring simulation results from simulink to matlab

1 回表示 (過去 30 日間)
동필
동필 2023 年 8 月 22 日
コメント済み: 동필 2023 年 8 月 22 日
The script below worked in the previous version of Matlab, but it does not work in the new version. Any advice please?
for k=1:50;
disp(['k=',num2str(k)])
y=sim('bungee_blocks');
if y>0
break
end
end
disp(['Safe k=',num2str(k)])

採用された回答

Walter Roberson
Walter Roberson 2023 年 8 月 22 日
I suspect that you might have configured Single Simulation Output; https://www.mathworks.com/help/simulink/gui/singlesimulationoutput.html
When that is enabled, the output of sim() is an object or struct array
  2 件のコメント
recent works
recent works 2023 年 8 月 22 日
編集済み: Walter Roberson 2023 年 8 月 22 日
yeah what you said is right. If you're using Simulink's Single Simulation Output mode, the sim function's output will be an object or struct array containing simulation results. This would explain why the variable y in your script is not a scalar value but an object or array.
for k = 1:50
disp(['k=', num2str(k)])
% Run the simulation
simOut = sim('bungee_blocks');
% Access the simulation output data
% Replace 'outputSignal' with the actual name of the signal you want to access
outputSignal = simOut.get('outputSignal'); % Adjust to your simulation output
% Check if the condition is met based on the simulation output
if any(outputSignal > 0)
break
end
end
disp(['Safe k=', num2str(k)])
outputSignal should be replaced with the actual name of the signal you are interested in from your Simulink model's output. You would need to explore the structure of the simOut object or struct array to locate the appropriate field names for in that case
동필
동필 2023 年 8 月 22 日
thank you very much.
but, i get the result :
==========
Operator '>' is not supported for operands of type 'Simulink.SimulationData.Dataset'.
Error occurred: bungeescript_help (line 19)
if any(outputSignal > 0)
===========
Any help in resolving this issue would be appreciated.

サインインしてコメントする。

その他の回答 (1 件)

recent works
recent works 2023 年 8 月 22 日
Check for Compatibility Issues
New MATLAB versions might introduce changes to functions, syntax, or behavior. Make sure that all the functions and components used in the script are compatible with the newer MATLAB version. Check the MATLAB documentation and release notes for any changes related to Simulink or other functions you're using.
Simulink Model Compatibility
Check if the "bungee_blocks" Simulink model is compatible with the new MATLAB version. Make sure that any required toolboxes or libraries are correctly installed and loaded.

カテゴリ

Help Center および File ExchangeDiagnostics についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by