MATLAB Answers

Paul Rae
0

Variables keep overwriting when i change the name

Asked by Paul Rae
on 19 Oct 2019 at 15:10
Latest activity Answered by Sulaymon Eshkabilov on 19 Oct 2019 at 19:32
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

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?

Sign in to comment.

Tags

Products


Release

R2019a

1 Answer

Answer by Sulaymon Eshkabilov on 19 Oct 2019 at 19:32

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.

  0 Comments

Sign in to comment.