How to avoid a newline in sprintf
Mostrar comentarios más antiguos
I'm writing a code that asks to choose a subject from a list. If a subject has already been chosen in a previous run, I want the dialog box to highlight it in a caption.
However, if I use sprintf to show the number of the subject, it will print it one line below. How can I avoid it?
Bonus question: is there a way to bold the output number?
list = string(1:10);
if exist('sj', 'var') == 1
[indx,tf] = listdlg('PromptString', {'Choose a subject', ...
'(Last chosen subject:' sprintf('%d)', sj)}, ...
'ListString', list, 'SelectionMode', 'single');
else
[indx,tf] = listdlg('PromptString', {'Choose a subject'}, ...
'ListString', list, 'SelectionMode', 'single');
end
if tf == 0
return
end
sj = str2double(list(indx));
1 comentario
Stephen23
el 22 de Jul. de 2022
"How can I avoid it?"
sprintf('(Last chosen subject: %d)', sj)
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!