Saving for loop value after each iteration
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone!
I am working on simulink MATLAB (2021b) where I am simulating a model. I am facing problem in saving the value of resistance, the code shown below give [ ] for the value of resistance.
Other two variables values are working fine for all 3 values of resistance. I am attaching my code
Any help would be appreciated! Thanks in advance
PS: The constant block picks all values of resistance at each iteration!
resistance = [0.72;0.983;0.221];
R = resistance;
for i =1:numel(R)
resistance=R(i)
simOut=sim('ModelName.slx','SimulationMode','normal')
a{i}=find(simOut,'Variable1')
b{i}=find(simOut,'Variable2')
c{i}=find(simOut,'resistance') %somewhere here
end
0 Kommentare
Antworten (1)
Image Analyst
am 20 Jan. 2022
Since resistance is already an array, simply delete the line where you overwrite the array with the i'th value of it:
resistance = [0.72;0.983;0.221];
R = resistance;
for i =1:numel(R)
simOut=sim('ModelName.slx','SimulationMode','normal')
a{i}=find(simOut,'Variable1')
b{i}=find(simOut,'Variable2')
c{i}=find(simOut,'resistance') %somewhere here
end
Now R and resistance both have all the original values.
4 Kommentare
Image Analyst
am 20 Jan. 2022
Let's see. Let's run it in MATLAB online:
resistance = [0.72;0.983;0.221];
R = resistance;
for i =1:numel(R)
resistance=R(i)
simOut=sim('ModelName.slx','SimulationMode','normal')
a{i}=find(simOut,'Variable1')
b{i}=find(simOut,'Variable2')
c{i}=find(simOut,'resistance') %somewhere here
end
Is that what you see? Anyway, I don't have Simulink so I can't run the sim() function.
Siehe auch
Kategorien
Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!