Wrong norm result in generated C code for MATLAB Function block (Simulink R2024b)
1 回表示 (過去 30 日間)
古いコメントを表示
I’m using MATLAB R2024b and Simulink R2024b ( 24.2.0.2863752 (R2024b) Update 5). In a MATLAB Function block I compute the Euclidean norm of a 3×1 vector:
function thrustArray = setupPhasing_inSimulink(timeVec, dv, t, m_full, thr, Ts)
thrustArray = zeros(3, length(timeVec));
if length(dv)/3 ~= length(t)
error('Length of the time and dv are not matched.');
else
n_burns = length(t);
end
m_before = m_full;
for i = 1:n_burns
dv_burn = dv((i-1)*3+1:i*3);
m_after = m_before/exp(norm(dv_burn)/thr.ve);
debug_norm_dv=norm(dv_burn);
...
end
end
When i run the Simulink and add the breakpoint I see following. The value of the dv_burn is following
dv_burn =
-0.02009
0.29035
-0.006347
When the break point hit and i ran to see what is the norm of the dv than i see
debug>> norm(dv_burn)
ans =
0.29111340575281
But when I look at the debug_norm_dv i should have see the same number but instead i see following
debug>> norm(dv_burn)
ans =
0.29111340575281
debug>> debug_norm_dv
debug_norm_dv =
4
debug>>
For me this gives me a clue that there might be something wrong with the compilation. I am running the model in Accelator mode.
adding some snippets of generated code I do not know if this helps.
c7_d2 = c7_norm(chartInstance, c7_dv_burn_data, c7_dv_burn_size);
c7_burn_size[0] = c7_b_size[0];
c7_d_loop_ub = c7_b_size[0] - 1;
for (c7_i9 = 0; c7_i9 <= c7_d_loop_ub; c7_i9++) {
c7_burn_data[c7_i9] = c7_b_data[c7_i9] / c7_d2;
}
tatic real_T c7_norm(SFc7_Copy_of_simOrbitControlInstanceStruct *chartInstance,
real_T c7_x_data[], int32_T c7_x_size[1])
{
ptrdiff_t c7_incx_t;
ptrdiff_t c7_n_t;
real_T c7_c_y;
int32_T c7_b_n;
int32_T c7_c_n;
int32_T c7_n;
int32_T c7_nx;
int32_T c7_var;
(void)chartInstance;
if (c7_x_size[0] == 0) {
c7_c_y = 0.0;
} else {
c7_nx = c7_x_size[0];
c7_n = c7_nx;
c7_b_n = c7_n;
c7_c_n = c7_b_n;
c7_var = c7_c_n;
c7_n_t = (ptrdiff_t)c7_var;
c7_incx_t = (ptrdiff_t)1;
c7_c_y = dnrm2(&c7_n_t, &c7_x_data[0], &c7_incx_t);
}
return c7_c_y;
}
If any of you would have some ideas please let me know, thank you very much !
2 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Test Model Components についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!