vec2ind is not supported for code generation?

1 回表示 (過去 30 日間)
K M Ibrahim Khalilullah
K M Ibrahim Khalilullah 2016 年 11 月 23 日
コメント済み: HASAN AL-KAF 2021 年 10 月 16 日
vec2ind is not supported for code generation. Is there any other way to solve this issue?

採用された回答

Walter Roberson
Walter Roberson 2016 年 11 月 23 日
In R2016b notation,
sum((1:size(vec,1)).' .* vec)
In earlier releases you would need
sum( repmat((1:size(vec,1)).', 1, size(vec,2)) .* vec)
  2 件のコメント
K M Ibrahim Khalilullah
K M Ibrahim Khalilullah 2016 年 11 月 24 日
Thanks for your answer
HASAN AL-KAF
HASAN AL-KAF 2021 年 10 月 16 日
Hi
The code doesn't give same result as vec2ind
for example vec= [1;0;1;0;1;1;5;0]
The result of vec2ind is 7.
The result of sum((1:size(vec,1)).' .* vec) is 50.
How can get exactly same result?. Becaue I want to transfer matlab code to c++.
Thank you.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by