MATLAB Coder Error : Output argument 'b' is not assigned on some execution paths? Help!

1 回表示 (過去 30 日間)
Hello guys! I am trying to convert the following code into C using MATLAB Coder and keep getting the same error which makes no sense to me because the code works fine on MATLAB.It keeps telling me 'Output argument 'b' is not assigned on some execution paths'.. What does it mean? Here's my code:-
function [ b ] = dct2C( M,N )
a = [1 2 3 4; 2 3 4 5; 3 4 5 6; 4 5 6 7];
c = [1 2; 3 4]
q_mtx = [16 11; 12 12];
for x = 1:2:M
for y = 1:2:N
b = a(x:x+1, y:y+1);
b = c*b*c';
b = b./q_mtx ;
a(x:x+1, y:y+1) = b;
end
end
end
  2 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 3 月 1 日
Hiroshi - why do you the following assignment
a(x:x+1, y:y+1) = b;
but then don't return a?
Hiroshi Nakamura
Hiroshi Nakamura 2015 年 3 月 2 日
OMG you are right Geoff! I should've returned A~ Nice call there! Thanks!

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

採用された回答

Image Analyst
Image Analyst 2015 年 3 月 1 日
It's saying that because it doesn't know what you're going to pass in for M and N. What if you passed in -30 and -5000? Would b get assigned? No, because the loop would never execute. Assign b to something just before the loop, like an error condition value like -1 or something.
b = -1; % Default if the loops never get entered.
  1 件のコメント
Hiroshi Nakamura
Hiroshi Nakamura 2015 年 3 月 2 日
Ahhhh that makes a lot of sense now.. Thank you! I really appreciate it! :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by