Printing a value from index array

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Printing a value from index array

harish3679
Hi,

for this experiment

choice = menu("beverages"{"beer","whiskey","brandy","vodka"});
disp(choice);

it asks me to select a number
menu
[1] beer
[2] whiskey
[3] brandy
[4] vodka

when I enter a number it just displays the number and excludes the strings
like beer, whiskey. .

Can I use listdlg instead?




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Printing a value from index array

Przemek Klosowski-7
On 07/23/2018 11:07 AM, harish3679 wrote:

> Hi,
>
> for this experiment
>
> choice = menu("beverages"{"beer","whiskey","brandy","vodka"});
> disp(choice);
>
> it asks me to select a number
> menu
> [1] beer
> [2] whiskey
> [3] brandy
> [4] vodka
>
> when I enter a number it just displays the number and excludes the strings
> like beer, whiskey. .
>
> Can I use listdlg instead?
>
Yes, but listdlg() is not yet widely available--for instance, the latest
Fedora version is 4.2.2 and it still doesn't have it.

As you indicated, menu() returns simply the menu sequence number---you
have to keep track of the item yourself:

itemlist = {"Neutron", "Electron", "Quark", "Proton", "Neutrino"};
octave:10> menu('particle',itemlist)
particle
   [ 1] Neutron
   [ 2] Electron
   [ 3] Quark
   [ 4] Proton
   [ 5] Neutrino

Select a number: 3
ans =  3
octave:11> disp(itemlist{3})
Quark