Variables keep overwriting when i change the name
Show older comments
I am trying to obtain 5 current values and 5 voltage values on my simulink project. The outputs of both are generated with a 'To Workspace' block. When i run simulink i get my variables 'current' and 'voltage' without a problem. However, when i change the circuit i change the variable names to 'current1' and 'voltage1' and when i run simulink. The new variables overwrite the first ones. Im trying to get values like current, current1, current2 etc but matlab only saves the most recent values. Does anyone know how to fix this?
1 Comment
Daniel M
on 19 Oct 2019
Are you saying that the output of current1 has overwritten the value of current? As in, both variables continue to exist in the workspace, but they have the same value?
Or do you mean that only current1 exists and current is deleted?
Answers (1)
Sulaymon Eshkabilov
on 19 Oct 2019
Hi,
You would need to create a small loop to run your simulink model via sim() command and every iteration results can be saved and not overwritten.
Here is very generic pseudo-code.
IN = [1.5, 2.2, 3.23, 4.1, 5.78, 6.12]; % Different values
for ii=1:numel(IN)
MY_var = b(ii); % This is the variable (constant) name that is in your Simulink model. It can be also series...
y(:,ii)=sim('SIM_MAT.slx');
end
Good luck.
Categories
Find more on Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!