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

Stephen23
Stephen23 2021년 2월 19일
편집: Stephen23 2021년 2월 19일
These lines are unlikely to do anything useful:
ii = ii +1;
jj = jj + 1;
MATLAB for loops already specify the loop variable. Your changes to ii and jj at the end of the loops will be simply overwritten at the start of the next loop iterations.
"During a debugg try I observed that the ii for loop is resetting to 1 after reaching the maximum value. How is it possible?"
Because that is what nested loops do.
Cyril CRIER
Cyril CRIER 2021년 2월 19일
편집: Cyril CRIER 2021년 2월 19일
Hi Stephen, thank you for your quick answer.
I've already tried to skip these lines
ii = ii +1;
jj = jj + 1;
but it gives me the same outcome (see picture)...
"Because that is what nested loops do."
Well it should do it when the above loop doese increment, but if I try with only 2 nested loops (ii and kk), ii recompute from one instead of breaking the loop... it's not easy to explain. Any way, why do I have 5100 lines, whenn I have normally maximum 900 calculation in those loops?
Walter Roberson
Walter Roberson 2021년 2월 19일
How exactly are you getting F_Spring in as a signal? Is column 1 of it the timestamps and you are using Discrete solver with timestep exactly equal to the difference in timestamps and algebra carefully designed to not have any 3:1 rate transitions?
It looks to me as if you have a From Spreadsheet block (or equivalent) and that you have signal interpolation going on that happens to be 3 samples for every time difference in the file.
Cyril CRIER
Cyril CRIER 2021년 2월 19일
Hi Walter,
I get F_Spring from a function (I extract a Variable with a To Workspace in parallel) and then via GoTo and From Blocks, to which I apply a gain of 2 (that gives me a 100x1 matrix).
"Is column 1 of it the timestamps and you are using Discrete solver with timestep exactly equal to the difference in timestamps and algebra carefully designed to not have any 3:1 rate transitions"
I have standard Solver parameters. I have to say that I don't understand what you said about it...
Walter Roberson
Walter Roberson 2021년 2월 19일
I suspect that you might have continuous solver in effect and that it is sampling three times as fast as you expected.
Cyril CRIER
Cyril CRIER 2021년 2월 22일
Hello Walter,
Should I change the solver parameters if it is the case?
And if yes, what should I choose?
Thanks
Cyril CRIER
Cyril CRIER 2021년 3월 9일
Hello, Istill don't have a solution for this Error. Somebody could halp me with this Solver stuff?
I'm a bit lost regarding the Solver's function I must say
Cyril CRIER
Cyril CRIER 2021년 3월 10일
편집: Cyril CRIER 2021년 3월 10일
Hello,
I'd like to make an update.
I found out that the calculation of my F_Spring variable that I use as an Input in the previous post, has a 100x1x51 dimension eventhough I perform a simple for loop to go through a 100x1 varable (column vector), see bellow:
F2 and Spring_cte are 2 constants:
The documentation of the solver is , of course, complete, but I don't understand everything I I don't want to change solvers without fully understanding the functionning or even not be sure that the issue is coming from it.
Somebody has an explanation to give, please? i'm still a bit lost...
EDIT: When I parameter all Sample Times, of the blocks in the Picture nr. 2, to -1 (inherited), I get a 100x1x5 variable type! It's better but still not what I'm looking for...
Thank you
Walter Roberson
Walter Roberson 2021년 3월 10일
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 2021년 3월 16일
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!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

제품

질문:

2021년 2월 19일

댓글:

2021년 3월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by