How to save the value of a variable inside a for loop in the MATLAb workspcae in each iteration (real-time)

조회 수: 8 (최근 30일)
Hi,
I have a simple for loop here and I would like to save the value of variable "a" in each iteration at the MATLAb workspcae. Becaseu I need to read that variable from workspcae simoultaneously and use it in Simulink. I do not need that value after completing the for loop (I could save it in a list), I need that value in real-time (once it gets updated) becaseu it will be used in a Simulink file as an input in real-time.
for i=1:10
a=i;
end

답변 (2개)

Souvik Das
Souvik Das 2023년 1월 31일
'global' or 'persistent' might satisfy your usecase. Attached below are the documentations for both:

Roya Salehzadeh
Roya Salehzadeh 2023년 2월 9일
I found the solution and wanted to share it here. The "set parameter" function in MATLAB could be used to adjust/change the value of a parameter inside a simulink model in real-time.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by