Bug with for loop increment
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!