i want to display a list in prompt dialogbox..how to usee break line in it likee i want to display text like that:
select songs from below list:
1.namee of songss:
2.name of songs:
3. name of songs:
etc
how can i display this in prompt dialog box

 Réponse acceptée

Geoff Hayes
Geoff Hayes le 22 Juil 2014

0 votes

Why not use a listdlg instead? It allows you to create a cell array of strings (in your case song titles) which is then displayed in a dialog that the user can select from
strs = {'1. name of song', '2. name of song', '3. name of song'};
prmpt = 'Select songs from below list:';
[s,v] = listdlg('PromptString',prmpt,'SelectionMode','multi','ListString',strs);
Try the above and see what happens!

10 commentaires

reema
reema le 22 Juil 2014
thanks! which song is selected then its store in strs veriable?
reema
reema le 22 Juil 2014
now i want to play song after seecting the number usin switch statement..how can i do this?
when mee aplly the switch statement with thiss see code:
strs = {'1. name of song', '2. name of song', '3. name of song'};
prmpt = 'Select songs from below list:';
[s,v] = listdlg('PromptString',prmpt,'SelectionMode','multi','ListString',strs);
switch strs
case 1
hmfr = dsp.AudioFileReader('21.mp3');
hap = dsp.AudioPlayer('SampleRate', hmfr.SampleRate);
while ~isDone(hmfr)
audio = step(hmfr);
step(hap, audio);
end
release(hmfr); % release the input file
release(hap); % release the audio output device
case 2
hmfr = dsp.AudioFileReader('21.mp3');
hap = dsp.AudioPlayer('SampleRate', hmfr.SampleRate);
while ~isDone(hmfr)
audio = step(hmfr);
step(hap, audio);
end
release(hmfr); % release the input file
release(hap); % release the audio output device
otherwise
hmfr = dsp.AudioFileReader('21.mp3');
hap = dsp.AudioPlayer('SampleRate', hmfr.SampleRate);
while ~isDone(hmfr)
audio = step(hmfr);
step(hap, audio);
end
release(hmfr); % release the input file
release(hap); % release the audio output device
end
then its givee errorr like:
>> prompt
SWITCH expression must be a scalar or string constant.
Error in prompt (line 4)
switch strs
how can i remove thisss error?
See switch for details on how to use this method of control flow. Note that the error is telling you that the switch expression must be a scalar or string constant. Look what you are using for that expression: strs which is a cell array of strings (and so is neither a scalar or string constant).
You should be using the s that is the returned value from listdlg as it is the integer index selection from the strs array that the operator/user has chosen.
Note that since you are allowing the multi option in
[s,v] = listdlg('PromptString',prmpt,'SelectionMode','multi',...
'ListString',strs);
then s may be a vector of indices (if the user selected more than one song). So your code should be able to handle this OR just replace multi with single to allow one selection only.
i do this just using :
I=char(strs);
switch I
....
end
i can run the code and get required output:
No, you must switch on the value that the user selected
[s,v] = listdlg();
switch(s)
case 1:
% etc.
end
reema
reema le 6 Août 2014
thankss its now work pefectlyy
reema
reema le 10 Août 2014
can i add images in list instead of text? and click the image and then cases aply
Geoff Hayes
Geoff Hayes le 10 Août 2014
I'm not sure - it may be one of those undocumented (and so unsupported) features that is possible when you start playing with the Java equivalent for the list box widget.
reema
reema le 10 Août 2014
i want to display in this list the images of persons instead name..
images of persons are display and then cases are apply when me select any image from this list

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by