Weird behavior of Popup Menu while dynamically populating data
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
Walter Roberson
2018년 9월 20일
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
Muhammad Umar
2018년 9월 21일
Walter Roberson
2018년 9월 21일
chan = get(hObject, 'Value'); %the number of the channel
chan_entry = contents{chan}; %the string corresponding to the channel
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!