Formatting cell array for the 'set' function in GUI

2 visualizaciones (últimos 30 días)
Aalaas
Aalaas el 4 de Oct. de 2016
Respondida: Dimitris Iliou el 11 de Oct. de 2016
This question might be a bit obvious, but I'm losing a lot of time with it...
I have a 1x2 cell like this:
strings_to_show =
'OF22' 'OF223'
I want it to convert to a variable in form of: {'OF22', 'OF223'} so that it can work in the 'set' function of the GUIs.
I would say that it is the same variable, but when I try to use the 'set' function this way:
(handleObj, 'String', {'OF22','OF223'});
it works, whereas when I try to use it like this:
(handleObj, 'String', strings_to_show );
It doesn't work.
How could I convert my 1x2 cell to the necessary format for the 'set' function??
Thank you very much for your time and effort!!!

Respuestas (1)

Dimitris Iliou
Dimitris Iliou el 11 de Oct. de 2016
My understanding of the issue is that you want to use a cell array to set the ‘String’ argument of a graphics object. I am assuming that the graphics object will be something like a ‘popupmenu’ or a ‘listbox’.
GUIs can be created using GUIDE or the ‘uicontrol’ command.
In case you are using the ‘uicontrols’ the following example might be useful:
function myui
% Create a figure and axes
f = figure('Visible','off');
ax = axes('Units','pixels');
surf(peaks)
Colors_to_choose = {'parula','jet','hsv','hot','cool','gray'};
% Create pop-up menu
popup = uicontrol('Style', 'popup',...
'String',Colors_to_choose ,...
'Position', [20 340 100 50]);
% Make figure visble after adding all components
f.Visible = 'on';
end
If you run the code, the ‘popup’ created will contain all the values that are encapsulated in the ‘Colors_to_choose’ variables.
In case you are using GUIDE, I have attached a .FIG and a .M files that contain a very simple GUI example that has a ‘popup’ menu and a ‘listbox’. For both objects I am using the following code to set the ‘String’ value:
strings_to_show = {'OF22','OF223'};
set(hObject, 'String',strings_to_show );
So to answer your question, no special formatting is required in order to pass a cell array to a ‘set’ function.
I suggest you try running the examples and see if they work for you and what differences they have from your code when you try to use the ‘set’ command.
Finally, you can find examples of the ‘set’ command in the documentation:

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by