Input command not showing the prompt until answer is put in the command window
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Currently I am using Matlab online, and whenever I run an input command, it won't show the prompt until I input an answer.
For example:
R = input("Input the Resistance in Ohms:\n");
Imax = input("Input the upper limit of current (greater than 0, in amps) to plot\n");
When I run my script, the command window is blank until I enter the answer. Once I input an answer, the command window displays the text that shouldve shown before my answer, and start working normally for any future input commands. To be more specific, i've added a picture of what happens. When I run the script above, my command window is blank, but once I input the number "5" as my answer, the "Input the Resistance in Ohms:" prompt will show up before my answer. Then the next input prompt will show up before I put in my answer as it should've done with the input command before.

I haven't seen any similar issues online and I unfortunetly cannot try the dekstop version of MATLAB at the moment. Any help is appreciated!
In case anybody wants to see the whole section of code this is in
%Clearing command window and workspace
clc
clear
%Asking for inputs
R = input("Input the Resistance in Ohms:\n");
Imax = input("Input the upper limit of current (greater than 0, in amps) to plot\n");
%Creating 200 numeric values of current to plot
I = linspace(0,Imax,200);
%Solving for voltage (V)
V = R*I;
%Plotting voltage vs current
plot(I,V,"k-")
0 Kommentare
Akzeptierte Antwort
Voss
am 18 Apr. 2024
The clc in your script is interfering with displaying the first input prompt at the right time. You can get around the problem by introducing a small pause after the clc and before the input (0.5 seconds worked for me):
%Clearing command window and workspace
clc
clear
pause(0.5)
%Asking for inputs
R = input("Input the Resistance in Ohms:\n");
Imax = input("Input the upper limit of current (greater than 0, in amps) to plot\n");
%Creating 200 numeric values of current to plot
I = linspace(0,Imax,200);
%Solving for voltage (V)
V = R*I;
%Plotting voltage vs current
plot(I,V,"k-")
4 Kommentare
Demetrius
am 11 Sep. 2024
Thank you! I was tearing my hair out trying to find a work-around. I'm teaching MATLAB for engineers this semester for the 1st time and I couldn't figure out why this was happening only in the online version.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!