Function output truncation

  • Follow


Hi,
I am looking for a way to truncate the output of a function in a signle line. I am currently using the following two-lines version :

<code=MATLAB>
       Y = fft(y);
       Y = Y(1:end/2);
</code=MATLAB> 

Any relevant help would be appreciated,

-- 

Tristan Martin, B.Ing 
Étudiant M.Sc.A. Génie Informatique
École Polytechnique de Montréal
Tristan.Martin@ieee.org
514.708.4856 (Mobile)
506.735.7685 (Résidence)
0
Reply Tristan 11/16/2010 1:51:03 AM

On 15/11/10 7:51 PM, Tristan wrote:
> Hi,
> I am looking for a way to truncate the output of a function in a signle
> line. I am currently using the following two-lines version :
>
> <code=MATLAB>
> Y = fft(y);
> Y = Y(1:end/2);
> </code=MATLAB>
> Any relevant help would be appreciated,

It can be done with subsref, but when you do that in a single line, you 
have to be able to predict the value that end/2 will evaluate to from 
the inputs -- possible in this case because length(Y) will be the same 
as length(y), but not possible in the general case.

If I recall, it can effectively be done in a single line even if you do 
not know the output sizes if you define an auxillary function:

IDX = @(Y,A,B) Y(A:B);

Y = IDX(fft(y), 1, end/2);

0
Reply Walter 11/16/2010 6:05:23 AM


1 Replies
297 Views

(page loaded in 0.072 seconds)

Similiar Articles:













7/27/2012 11:59:25 PM


Reply: