I am trying to work out this equation with Simulink.
[c,fxval]=max(abs(C(ms2:ms20)));
ms2 = 0.002
ms20 = 0.02
C is a complex array that i have derived in previous part..
I noticed i can't use the MIN block to get the maximum.
Can advise me what is the suitable block that i should use to get the maximum and return me the index of maximum value?
Many thanks.
The Simulink version that comes with matlab 2008b got one MinMax block, maybe you have an older version, anyway you can find Max with Min function, just multiply your vector by -1 and the minimum value will became the maximum value.
but can i set the Min block to analyse for maximum value on specific range instead of whole range? I m using 2007b
yes i understand... May be i didn't make my idea clearly enough due to my weak english.
Actually what is the block that i can use to search maximum within specific index of an array...
Says that, i have
x = [1 3 5 7 2 4 8]
I would like to get the maximum from index 2 to 5. So my maximum value would be 7 .. not 8.. And the returned index for maxima's index is 4.
Please advise which block i can use for this purpose.
If i use min block.. it will trace for the maxima value in the whole array and doesn't meet my requirement.
Thank you.
"st " <cel...@hotmail.com> wrote in message
news:igoggo$3m$1...@fred.mathworks.com...
>
> yes i understand... May be i didn't make my idea clearly enough due to my
> weak english.
>
> Actually what is the block that i can use to search maximum within
> specific index of an array...
>
> Says that, i have
> x = [1 3 5 7 2 4 8] I would like to get the maximum from index 2 to 5. So
> my maximum value would be 7 .. not 8.. And the returned index for maxima's
> index is 4.
>
> Please advise which block i can use for this purpose.
>
> If i use min block.. it will trace for the maxima value in the whole array
> and doesn't meet my requirement.
>
> Thank you.
>
Then use the selector block before the min/max block to select the indices
of interest:
http://www.mathworks.com/help/toolbox/simulink/slref/selector.html
HTH,
Arnaud
Then may i know what block that i can use to return the INDEX of my maximum value?
I will be searching from the result of FFT absolute's value.
Thanks
"st " <cel...@hotmail.com> wrote in message
news:igu7ns$o3g$1...@fred.mathworks.com...
Here's one solution, not sure if there's a better one. Use the relational
operator to do an equality test between the max value and the original
vectorized signal. The output of the relational block will be a vectorized
signal of the same dimension as your original signal with zero everywhere,
except where the maximum occurs, at which points it will have a one. Feed
that signal to a Find block to detect non zero elements, the output will be
a variable-size signal with the indices of the maximum values. Make sure you
select the one-based index mode in the Find block. The Find block also
requires a discrete sample time.
http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/slref/relationaloperator.html
http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/slref/find.html
HTH,
Arnaud
Thank your for your reply.
But i have tried to work out the element selection with Selector..
and still i can;t get the thing right....
Below is my scenario, i hope u may comment what i have done wrong...
I am trying to work out the below statement with Simulink
[c,fxval]=max(abs(C(83:883)));
- I was using Maximum block, Abs block, and Selector Block ..
- Assume that C is the result of FFT from Y signal.
- The length of C is 32768
I gave two tries for that and put a Displayer block at the output of
Selector block:
1st: Using Selector block
My setting for parameters are as below:
- Number of input dimension = 1
- Index Option: Index Vector Dialog
- Index : [83 883]
- Input size port : -1
Problem: I only have 2 result returned all the time. Suppose i will
have (883-83=800) results displayed on my Displayer Block. Please tell
me where is my mistake...
2nd: Using Function Block Parameters (Fcn)
I replace the Selector block with the Fcn and have my expression
defined as C(83:883).. But this doesn't work out and return me error
as below:
Error while parsing expression: u(83:883)
in 'RealTime2/Fcn'
token ":" was found, where as ")" was expected.
Again, please tell me why i can't simply replace the selector like
this way.
What should i do in order to work out the C(83:883) which selected the
elements in array C from index 83 to 883. Many thanks~