Weird behavior of Popup Menu while dynamically populating data
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
I am fairly new to matlab and trying to implement a feature where I can populate data in table based on popup menu selection. Here is sample code
for chan = 1:n
if (chan > 1)
channels = channels + newline + "Ch. " + chan;
else
channels = "Ch. " + chan;
end
end
set(handles.popupMenu,'String', channels,'Value', 1);
handles.popupMenu = Popup Menu
n = 3
It does work good. It outputs 3 Options in Popup Menu, Channel 1 , Channel 2 and Channel 3. Firstly How can I set the values too? Because when I use the same array it gives me error no Value property found
Secondly on changing the value of popup menu
% --- Executes on selection change in coloredChannel.
function coloredChannel_Callback(hObject, eventdata, handles)
contents = get(hObject,'String');
fprintf('%s\n', contents)
Returns
CCChhhaaannnnnneeelll 123
as response.
What is the above response and how can I get the selected item value or string.
Réponses (1)
Walter Roberson
le 20 Sep 2018
When you set the String property of a uicontrol with a scalar string object or a character row vector, then the content is analyzed for | characters and newlines to determine whether multiple rows should be created. The content is converted to a char array with the appropriate number of rows, and that is what is stored in the String property. Then when you retrieve the String property, the usual rules apply for fprintf() of arrays: namely that values are displayed down columns first (that is, linear indexing is used.)
I suggest
contents = cellstr( get(hObject,'String') );
fprintf('%s\n', contents{:})
2 commentaires
Muhammad Umar
le 21 Sep 2018
Walter Roberson
le 21 Sep 2018
chan = get(hObject, 'Value'); %the number of the channel
chan_entry = contents{chan}; %the string corresponding to the channel
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!