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

 採用された回答

Star Strider
Star Strider 2018 年 4 月 16 日

0 投票

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 件のコメント

Ahmed Rabeea
Ahmed Rabeea 2018 年 4 月 16 日
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
Star Strider
Star Strider 2018 年 4 月 16 日
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.
Ahmed Rabeea
Ahmed Rabeea 2018 年 4 月 16 日
Same thing and the only way to resolve it is by close the matlab and reopen it
Star Strider
Star Strider 2018 年 4 月 16 日
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.
Ahmed Rabeea
Ahmed Rabeea 2018 年 4 月 16 日
YES!! _ clearvars_ works
Thanks a lot
Star Strider
Star Strider 2018 年 4 月 16 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (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