Number of push button change
조회 수: 1 (최근 30일)
이전 댓글 표시
I have an audio that I've split into 2 segments. I'd like to plot the audio file and add 2 push buttons in the figure, in order to play each segment. This part is quite standard to do. What if I decide to split the signal in 3 or 4, or more? How can I do that without creating all the possible push button? Is there any cleaver way of do it? Using a for loop uicontrol() would be a solutions.
댓글 수: 0
채택된 답변
Image Analyst
2019년 1월 18일
편집: Image Analyst
2019년 1월 18일
Have an edit field or scrollbar/slider that allows the user to specify the number of segments to split it up into. Then have a single pushbutton that reads the number from the edit field and does its thing
numSegments = handles.sldNumSegments.Value; % For a scrollbar/slider in GUIDE
numSegments = str2double(handles.edtNumSegments.String); % For an edit text box in GUIDE
You could do the same thing to have the user say what segment to play, so they could specify to split it up into 9 segments and play segment #4 for example.
Attach your fig file and m file if you need any more help.
댓글 수: 5
Image Analyst
2019년 1월 20일
Of course it didn't work. Because you're not using GUIDE. You created the popup on your own for some reason with uicontrol. So it's handle is not handles.popupmenu, but the name you gave it, which is selectSeg. So to get the value you need to refer to selectSeg.Value. If you want it in a separate variable for some reason, you could do
popup_sel_index = selectSeg.Value;
추가 답변 (1개)
Kevin Phung
2019년 1월 18일
Instead of having a pushbutton per segment, perhaps you can create a listbox that will be populated with the number of segments in your audio file.
Pushing the pushbutton will then play the selected segment.
댓글 수: 2
Image Analyst
2019년 1월 19일
Would have been no problem with GUIDE where every callback function has access to ALL the controls and their values. But since you've accepted this answer, I guess you want to keep attempting to do it this way. I'm sure Kevin will answer shortly.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!