Using GUI Designer to convert integer inputs to exponential form (convert MHz to integer Hertz)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Scotty Mac
am 14 Sep. 2023
Kommentiert: Scotty Mac
am 15 Sep. 2023
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 Kommentare
Stephen23
am 14 Sep. 2023
"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)
Akzeptierte Antwort
Walter Roberson
am 14 Sep. 2023
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!