Wednesday, 15 May 2013

GUI pop-up menu in MATLAB -


I have a pop-up menu with content of 5,10,15,20 in that menu using the switch I have made it

  val = get (hobject, 'value'); Switch case case '5' n = 5; Case '10' n = 10; Case '15' n = 15; Case '20' n = 20; End guide (HObject, handle);   

Where this output represents the number of pictures it presses the search button in the same GUI window, it calls another function where I need to use this 'N' .

  for i = 1: n% store top n matches ... tempstr = char (resultNames (index (i))); Fprintf (fid, '% s \ r', tempstr); Disp (resultNames (index (i))); Disp (sortedValues ​​(i)); Disp ('') end   

How do I pass that code or function to 'n'? Any correct answer is commendable.

Good, it is wrong and unnecessary to start with your switch statement The value property of a dropdown is not present in the current selection, it is the index in the current list. To get the string value of the currently selected list item, you will:

  content = cellstr (get (hObject, 'string'))% returns content as cell contents   

This is definitely a handle assuming hObject The dropdown indicates the box - which will be only if you are in a callback that is called by land dropdown. Security had been raised. Also, note that there is no need to change string value through unconnected switch statement; You can only use str2num or str2double functions.

Finally, if you need access to the value of the dropdown from outside your own callback, you will need to use the handle structure, which will be used in every callback (or in your sample , Has been passed from guidata ). There will be an area with the same name in the name of your dropdown - it will be handled by which you can access your properties.

No comments:

Post a Comment