Info
この質問は閉じられています。 編集または回答するには再度開いてください。
failed to determine the appropriate size in find
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I'm having some problem getting matlab coder to identify a variable used as result from find as a scalar. Below is a simple testcase:
function [ y ] = a_test()
x = zeros(5, 1);
k1 = find(x > 1, 1);
if (isempty(k1))
k1 = 0;
end
y = x(1:k1);
end
The coder fails to generate code due in the last line because it cannot infer that k1 is a scalar. Is there a way of handling this?
Thanks, -- Octav
0 件のコメント
回答 (3 件)
Grzegorz Knor
2012 年 2 月 27 日
What should be the y?
Maybe replace:
if (isempty(k1))
k1 = 0;
end
with:
if (isempty(k1))
k1 = 1;
end
0 件のコメント
Jan
2012 年 2 月 27 日
While in you code k1 is a scalar, 1:k1 is not when k1 equals 0.
function y = a_test()
x = zeros(5, 1);
k1 = find(x > 1, 1);
if isempty(k1)
y = ???;
else
y = x(1:k1);
end
0 件のコメント
Fred Smith
2012 年 2 月 27 日
Try this:
function [ y ] = a_test()
x = zeros(5, 1);
k1 = find(x > 1, 1);
if (isempty(k1))
k1 = 0;
end
y = x(1:k1(1)); % Added k1(1)
end
HTH,
Fred
2 件のコメント
Jan
2012 年 2 月 28 日
After the IF-block, k1 is always a scalar. Therefor k1(1) is not useful. In addition y=x(1:k1(1)) still fails, if k1 is 0, because 1:0 is empty.
Fred Smith
2012 年 2 月 29 日
k1 is always scalar but MATLAB Coder does not know that. It does know that k1(1) is always a scalar. x(1:0) is legal and returns an empty matrix. I don't know what the intended behavior is in this case but the changed code matches the behavior of Octav's original code.
-Fred
この質問は閉じられています。
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!