fprintf not printing to command window when asking for input.
이전 댓글 표시
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
답변 (2개)
Star Strider
2024년 9월 17일
0 개 추천
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).
댓글 수: 1
Walter Roberson
2024년 9월 17일
Walter Roberson
2024년 9월 17일
0 개 추천
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.
댓글 수: 1
Rasmus Adrian
2026년 2월 23일 15:02
this saved me from a lot of unnecesary work!!!
카테고리
도움말 센터 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!