help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getting the first element of a possibly empty list


From: Tom Holroyd
Subject: getting the first element of a possibly empty list
Date: Tue, 17 May 2005 23:45:35 -0400
User-agent: Mozilla Thunderbird 1.0.2-1.3.2 (X11/20050324)

Here's one way

>> x = [4 3 2 1];
>> x(1:min(1,size(x,1)))

ans =

     4

>> x = [];
>> x(1:min(1,size(x,1)))

ans =

   Empty matrix: 1-by-0

This can even be shortened to x(1:min(1,end)).  This works in Octave as well.
Is there a simpler way?

--
Dr. Tom Holroyd
"A man of genius makes no mistakes. His errors are volitional and
are the portals of discovery." -- James Joyce



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]