fprintf not printing to command window when asking for input.
25 次查看(过去 30 天)
显示 更早的评论
Hello. I am working on a Jukebox to play a song that corrisponds with set number (this part is not the issue I am just trying to provide some context).
When the code is run I would like the Opening menu to appear in the command window so the user can see the song choices before being prompted to enter an input. The problem is that when I run the code it does not print any of my text and just waits for an input. I think it has something to do with the fact that other than declaring some variables, there is nothing happening before the first fprintf. I am not getting any error or warning messages on my end.
Is this a quirk of using the online version? I am using the online verison of MATlab because I am having techinal issues with installing the desktop version.
(This is not all of my code, I chose to only share what is relevent to my issue)
clear
clc
close all
%% Declarations
rate = 32768; % sampling rate
songs = 1:9;
octave = 0;
speed = 0;
% Opening menu. Give list of options
fprintf(['Welcome to Jukebox.\n-------- SONG MENU --------\n 1 |'...
' Bohemian Rhapsody \n 2 | ' ...
'Dies Irae \n 3 | Entry Into Valhalla \n 4 | Fur Elise \n 5 | ' ...
'Game of Thrones Theme \n 6 | He''s a Pirate \n 7 | Megalovania ' ...
'Long \n 8 | Paint it Black \n'])
% Prompt user for selection, and check validity of choice
songNum = input(['Enter the number of the song you wish to play --> \n']);
while songNum < 0 || songNum > 9 || mod(songNum,1) ~= 0
songNum = input('Try again --> ');
end
0 个评论
回答(2 个)
Star Strider
2024-9-17
When I run your input line, it prints this to my Command Window:
Enter the number of the song you wish to play -->
and then waits for an input. It works for me (R2024b).
Walter Roberson
2024-9-17
Is it possible that you are using LiveScript ? When you use LiveSript, the output of fprintf() goes to the script window rather than to the command window.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!