find non zero elements in array
显示 更早的评论
im trying to implement find non zero elements without using "find' toolbox in simulink. im using matlab function block as shown on the screenshot
function y = non_zero(u)
x=find(u);
y=x


回答(1 个)
Soniya Jain
2021-7-10
As mentioned in the error, that y is non-tunable, so have you tried to select the 'Variable Size' checkbox by specifying the upper bounds in the Size box?
Also, find function will return the index of the non zero elements in a vector, so if you want values at the index, you can code in the following way:
function y = non_zero(u)
x = find(u); % will return index of non-zero elements
y = y(x);
end
3 个评论
Le Dyk Zuy
2021-7-10
Soniya Jain
2021-7-11
So have you tried to select the 'Variable Size' checkbox by specifying the upper bounds in the Size box?
Le Dyk Zuy
2021-7-12
类别
在 帮助中心 和 File Exchange 中查找有关 Code Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!