Question about sprintf function.
1 次查看(过去 30 天)
显示 更早的评论
Here's my syntax:
bm= input ('value');
val = 43 ;
A = sprintf('%d',val);
%if i declare A(1), ans is 4, which is correct.
c=0;
A1 = A(1) .* (bm^(c))
Why is it that if my bm = 8, A1 = 52? its like 4 * 8 = 52. i think my error here is the sprintf function.
0 个评论
采纳的回答
Image Analyst
2012-9-29
Why not just do
A1 = val;
???? bm^c is just 1, and I'm not sure if you really wanted to take the first digit of 43. If you did, you could just do
A1 = floor(A/10); % As long as A is less than 100.
instead of using sprintf. Is A really some sort of ASCII or hexadecimal number?
6 个评论
Image Analyst
2012-9-29
Yes, you're right. It does really only go to 16. I didn't have a "clearvars" or "clear all" in there so there was left over stuff in theNumbers from prior test runs. This shows one good reason to use clear (though I know Jan doesn't like it) is to avoid goofs like this. Sorry about that.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!