error with sprintf add operation between 2 terms resulting in string
2 ビュー (過去 30 日間)
表示 古いコメント
I used sprintf Mt1a to receive a value which someone not experienced with matlab would understand the value ,there appears to be a conflict in " Mt1a+Mt2a " which gives me multiple values ,i tried using str2double to fix my result but it returns NaN ,how can i fix the result for b ?
b=sprintf('%.0f\n',a./str2double(Mt1a+Mt2a)) % ==>how i attempted to use str2double
Mt2a=66539;
Fa=88050;
d2p=37;
p=6;
rb=0.08;
tga2p=p/(pi*d2p);
x=(tga2p+rb)/(1-(tga2p*rb));
Mt1a=sprintf('%.0f\n',Fa*(d2p/2)*x)
a=Fa*(d2p/2)*tga2p;
b=a./(Mt1a+Mt2a)
2 件のコメント
採用された回答
Star Strider
2021 年 3 月 25 日
‘I used sprintf because that's the only command i know of ,to get from Mt1a= 2.152845579898380e+05 toMt1a=215285.’
If you want to eliminate the fractional part of the numbers, use the round, fix, floor or ceil functions, depending on the result you want. (I provided a link to round, links to the others are in that documentation.)
3 件のコメント
その他の回答 (1 件)
Steven Lord
2021 年 3 月 25 日
Do you want to concatenate a number and a piece of text together?
a = '1234'; % a is a char vector
b = 5;
c = [a, num2str(b)]
as = "1234"; % as is a scalar string
b = 5;
cs = as + b % automatically converts 5 to "5" then appends it to as
Or do you want to add them?
d = a + b % add 5 to the ASCII values of the characters '1', '2', '3', and '4'
d2 = double('6789')
f = str2double(a)+b % add 5 to the number represented by a
f2 = double(as)+b % double on a string array converts it to the number it represents
参考
カテゴリ
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!