Hi all, why does program repeat the highest value each time I run it? Note: When I choose a higher value the program run correctly
The issue in these lines
promt4 = 'Please enter the number of bits: ';
N = input(promt4); %Number of bits
if N <= 128
Nb = N;
else
promt5 = 'Please enter the correct number of bits between 0-128: ';
N = input (promt5);
Nb = N;
end

 Akzeptierte Antwort

Star Strider
Star Strider am 16 Apr. 2018

0 Stimmen

Your code runs correctly, as far as I can determine.

If the original ‘N’ is less than or equal to 128, the else condition does not execute. If the original ‘N’ is greater than 128, the else condition executes appropriately. (The only change I would add is also to test that ‘N’ is greater than 0.)

What do you want your code to do?

6 Kommentare

I know that but when I enter N like for example 10 it will give me the things that I want, but when I run the program again and I enter the value of N less than 10 The answer will be the same for N equal 10 even if I type clc
The code you posted works as I described.
The clc call only clears the Command Window. It does not clear the variables.
Try this instead:
clear N Nb
just before the ‘promt4’ assignment.
Same thing and the only way to resolve it is by close the matlab and reopen it
I cannot determine what the problem is from the code you posted. I may be able to if I see more of your code.
You can also see if clearvars works.
YES!! _ clearvars_ works
Thanks a lot
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by