Input command not showing the prompt until answer is put in the command window

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-")

 Réponse acceptée

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 commentaires

Thank you! This worked perfectly.
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2024a

Question posée :

le 18 Avr 2024

Commenté :

le 11 Sep 2024

Community Treasure Hunt

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

Start Hunting!

Translated by