Using GUI Designer to convert integer inputs to exponential form (convert MHz to integer Hertz)
3 次查看(过去 30 天)
显示 更早的评论
My orginial inputs in a .m function are in Hertz and then combined in an aray as follows:
x1 = 5700e6
x2 = 4750e6
x3 = 4950e6
x_array = [x1, x2, x3]
In Matlab Designer/GUI where the user can enter values in MHz, how do I input the values as say 5700 MHz and have it convert it to 5700e6?
This is what I have currently, but it doesn't match the orginal above:
x1 = str2double(app.EditField_x1.Value);
x1 = x1 * 10e5;
x_array = [x1, x2, x3];
The 'double' could be the issue.... Should it be str2num or something else? Then can I multiply that value to represent it as a Hertz value (to match the form 5700e06)? I can't seem to get it to match and it is affecting my output.
Thanks in advance!
2 个评论
Stephen23
2023-9-14
"how do I input the values as say 5700 MHz and have it convert it to 5700e6?"
num = str2double('5700');
fprintf('%.30f\n', num*1e6, num*10^6, 5700e6)
采纳的回答
Walter Roberson
2023-9-14
If the user is expected to enter 5700 and that is to represent the same as 5700e6 would, then you should be multiplying by 1e6 instead of by 1e5.
str2double() is better than str2num() in the majority of cases.
format long g
x1 = '5700'
x1n = str2num(x1)
x1d = str2double(x1)
x1n - x1d
x2 = '5700e6'
x2n = str2num(x2)
x2d = str2double(x2)
x2n - x2d
x1d * 1e6 - x2d
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!