program repeat the highest value each time I run it

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

 采纳的回答

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 个评论

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

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by