linspace not working on MATLAB Coder

7 ビュー (過去 30 日間)
Matteo Paiano
Matteo Paiano 2021 年 9 月 17 日
コメント済み: Matteo Paiano 2021 年 9 月 17 日
I have some problem with linspace operator inside simulink.
I want to take a decision among a finite set of angles, which I define as
delta = linspace(-r_max*Tc_usbl,r_max*Tc_usbl,decisions)
r_max being the maximum angular velocity, Tc_usbl the control period, 'decisions' the number of angles I want in my set. In the Command Window everything works fine; and iy should work in Simulink too, since I succesfully tried
function fcn()
delta_max = -0.1; decisions = 3;
for delta = linspace(-delta_max,delta_max,decisions)
delta
end
But my code actually is
function fcn(r_max,Tc_usbl,decisions)
for delta = linspace(-r_max*Tc_usbl,r_max*Tc_usbl,decisions)
delta
end
Where all arguments are static parameters from the Workspace.
I get the following error:
FOR loop index expressions of unknown size are only supported if they are of the form A:B or A:B:C
If it is not possible to use linspace the way I'd like to, does someone has any other idea? But how can I get with colon something similar to
linspace(-pi/4,pi/4,2)

採用された回答

Stephen23
Stephen23 2021 年 9 月 17 日
編集済み: Stephen23 2021 年 9 月 17 日
In MATLAB it is usually better to loop over indices. Perhaps this would work:
V = linspace(-r_max*Tc_usbl,r_max*Tc_usbl,decisions);
for k = 1:numel(V)
delta = V(k)
... do whatever with delta
end
  1 件のコメント
Matteo Paiano
Matteo Paiano 2021 年 9 月 17 日
I really appreciate that! Such an elegant and simple solution! How silly of me

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by