MATLAB Functionブロックの使用方法

23 visualizaciones (últimos 30 días)
O.E
O.E el 24 de Nov. de 2017
Comentada: O.E el 6 de Dic. de 2017
MATLAB Functionブロック内でSwitch文を用いてConstantの値を選択して、出力する機能を実装しビルドしたところ
以下のエラーメッセージが出力されビルドが中止されました。
変数 'code' は、いくつかの実行パス上で完全に定義されていません。
関数 'MATLAB Function' (#35.2845.2849)、行 126、列 4:
function y = fcn(u,ck,th)
switch ck
case 0
jug = u >= th(1,:);
jug = sum(jug);
switch jug
case 0
code = 0;
case 1
code = th(1,4);
case 2
code = th(1,3);
case 3
code = th(1,2);
case 4
code = th(1,1);
end
case 1
jug = u >= th(2,:);
jug = sum(jug);
switch jug
case 0
code = 0;
case 1
code = th(1,4);
case 2
code = th(1,3);
case 3
code = th(1,2);
case 4
code = th(1,1);
end
case 2
jug = u >= th(3,:);
jug = sum(jug);
switch jug
case 0
code = 0;
case 1
code = th(1,4);
case 2
code = th(1,3);
case 3
code = th(1,2);
case 4
code = th(1,1);
end
case 3
jug = u >= th(4,:);
jug = sum(jug);
switch jug
case 0
code = 0;
case 1
code = th(1,4);
case 2
code = th(1,3);
case 3
code = th(1,2);
case 4
code = th(1,1);
end
case 4
jug = u >= th(5,:);
jug = sum(jug);
switch jug
case 0
code = 0;
case 1
code = th(1,4);
case 2
code = th(1,3);
case 3
code = th(1,2);
case 4
code = th(1,1);
end
case 5
jug = u >= th(6,:);
jug = sum(jug);
switch jug
case 0
code = 0;
case 1
code = th(1,4);
case 2
code = th(1,3);
case 3
code = th(1,2);
case 4
code = th(1,1);
end
case 6
jug = u >= th(7,:);
jug = sum(jug);
switch jug
case 0
code = 0;
case 1
code = th(1,4);
case 2
code = th(1,3);
case 3
code = th(1,2);
case 4
code = th(1,1);
end
case 7
jug = u >= th(8,:);
jug = sum(jug);
switch jug
case 0
code = 0;
case 1
code = th(1,4);
case 2
code = th(1,3);
case 3
code = th(1,2);
case 4
code = th(1,1);
end
end
y =code;
変数ckはトリガ、thはConstantの値です。

Respuesta aceptada

Jiro Doke
Jiro Doke el 28 de Nov. de 2017
Editada: Jiro Doke el 29 de Nov. de 2017
全ての switch-case 構文に otherwise を追加してみてください。
つまり、例えば jug が0、1、2、3、4 以外 のケースにも対応していなければならないという事です。0、1、2、3、4しかありえないときは、 case 4 otherwise に変えれば良いと思います。
  1 comentario
O.E
O.E el 6 de Dic. de 2017
解決いたしました。
ありがとうございます。

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre ループと条件付きステートメント en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!