help-octave
[Top][All Lists]
Advanced

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

Re: initialising a cell array using an array


From: Francesco Potorti`
Subject: Re: initialising a cell array using an array
Date: Tue, 21 Feb 2006 23:34:19 +0100

I answer myself:

>I have this code:
>
>  speeds=[1, 2, 5.5, 11];      # Available speeds
>
>    choices=cell();            # create a menu of available speeds
>    for i = 1:length(speeds)
>      choices{i} = sprintf("%g Mb/s", speeds(i));
>    endfor
>    sel = menu("Nominal speeds:", choices{:});
>
>In order to create the argument list for menu, I use a cell array.  But
>initialising the cell array needs a loop.  Can I vectorise the loop?

Yes, if you do like this:

    choices = concat(num2str(speeds'), repmat(" Mb/s",size(speeds')));
    sel = menu("Nominal speeds:", cellstr(choices){:});

Are there better ways?

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 313 8091
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
Web: http://fly.isti.cnr.it/           Key:   fly.isti.cnr.it/public.key



-------------------------------------------------------------
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]