Bug with for loop increment

3 visualizzazioni (ultimi 30 giorni)
Cyril CRIER
Cyril CRIER il 19 Feb 2021
Commentato: Cyril CRIER il 16 Mar 2021
Hello,
I am using a funciton in a simulink Model. This function has 5 Inputs and 1 output.
I need a 100 lines * 9 col. as output but I get a 5100 * 9 matrix...
During a debugg try I observed that the ii for loop is resetting to 1 after reaching the maximum value. How is it possible?
I know that the output is writting 3 times in the first column and I habe to work on that, but even though the output fills the column after the end of the first 100 values (kk) I should get max 300 values in one column, not 5100!!!
THe actual code is below:
length(F_Spring) = 100
FS_op_all_hill is a 100 lines per 3 columns matrix
Axial_Fric is a 3 lines per 1 column matrix
Lever_Arm_Opening is a constant
Open_out should be a 100 lines oer 9 columns matrix.
function Open_out = fcn(F_Spring, FS_op_all_hill, Axial_Fric, Lever_Arm_Sp,Lever_Arm_Opening)
Open_out = zeros(100,9);
y = zeros(100,3);
%%!!! Attention, has to be modified : result should be a matrix of 100 lines for 9 columns !!!!!%%%
for jj = 1 : 3 : 9
for ii = 1 : 3
for kk = 1 : length(F_Spring)
y(kk,ii) = F_Spring(kk,1) - FS_op_all_hill(kk,ii);
Open_out(kk,jj) = (y(kk,ii) - Axial_Fric(ii,1)) * Lever_Arm_Sp(kk,1) / Lever_Arm_Opening *(-1);
end
ii = ii +1;
end
jj = jj + 1;
end
Hier is a screen shot of a part of the Simulink model:
Has anybody an idea where the Problem comes from?
Thanks
  11 Commenti
Walter Roberson
Walter Roberson il 10 Mar 2021
I don't want to change solvers without fully understanding the functionning
It could take a long time to fully understand the implications of all of the solver parameters, and you are unlikely to learn the implications without experimenting.
Take a copy of your system, change the solver to discrete; if everything goes haywire, revert to the continuous version.
Cyril CRIER
Cyril CRIER il 16 Mar 2021
Hello,
So I was not able to resolvev completely the problem with a "clean" solution, meaning with an other solver or something like that.
Instead, I just limited the points to last in the block "To Workspace" (see picture).
At least now, the variable created is limited to 100 values which ürevent the simulation to give five time the 100 first values.
I'll post a cleaner solution if I find one.
Thanks for the help anyway!

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by