Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get a nonzero elements of an input vector in SIMULINK?

1,017 views
Skip to first unread message

Ryan Wang

unread,
Jan 22, 2006, 11:03:58 AM1/22/06
to
Hello, all

Can anyone tell me what blocksets should I use to do the

same job as MATLAB function "find" does?

For example, if I have an input signal x = [1 0 -10 -2 2 3]

and I want to find elements great than zero, so the output

signal should be y =[ 1 2 3], how do I do this with

SIMULINK blocks?

Thanks for your help.

Navan

unread,
Jan 23, 2006, 3:02:46 PM1/23/06
to

The Variable Selector block in Signal Processing blockset supports
logical indexing. But in Simulink the dimensions cannot change. So if
you use x > 0 as indices the output will be y = [1 2 3 0 0 0].

Navan

Ryan Wang

unread,
Feb 16, 2006, 6:20:31 AM2/16/06
to
> The Variable Selector block in Signal Processing blockset supports
> logical indexing. But in Simulink the dimensions cannot change. So
> if
> you use x > 0 as indices the output will be y = [1 2 3 0 0 0].
>
> Navan

Oops, that's too bad. Maybe I should write a s-function istead.
Anyway, thanks for your concern.

Ryan

kumaraguru Mollin

unread,
Feb 16, 2006, 7:41:16 AM2/16/06
to
hi Ryan,
In S-function v need to specify size of the output!!!.is generic
s-function is possible(with variable output)?
so i think even s-function will not workout for that problem.

Regards,
Mollin

&#26472

unread,
Feb 16, 2006, 9:20:45 AM2/16/06
to
Hi:Ryan Wang .
If you want to ger a nonzero elements of an input vector, and at
the same time change the dimensions of the vector, you can use the
following program:

x=input('input a arry, x=');
m=0;
n=length(x);
for i=1:n
if x(i)>0
m=m+1;
y(m)=x(i);
end
end
y

Ryan Wang

unread,
Feb 17, 2006, 12:02:40 PM2/17/06
to
Hi,杨小秋

Thanks for your help first and your code does work in

MATLAB environment BUT failed in SIMULINK model.

Ryan

Ryan Wang

unread,
Feb 17, 2006, 12:19:51 PM2/17/06
to
Hi, Mollin

Thanks for ur kind reminder that the size of the ouput should be
initialized or defined in advance, which prohibits me from creating
dynanmical sized ouput.
Oh gee, what do I suppose to do?

Ryan

Jordan

unread,
Feb 17, 2006, 1:41:30 PM2/17/06
to
Since you can't dynamically size the output, you have to look at what
you are doing with the output and determine if you can make it work a
fixed-length vector that is padded with zeros or some other value.
What do you want to do with this output after you get your vector?

hina.fa...@gmail.com

unread,
May 31, 2018, 7:27:25 AM5/31/18
to
Use a enabled subsystem as shown as by Sebastian Castro in https://www.mathworks.com/matlabcentral/answers/133397-simulink-output-only-non-zero-values
0 new messages