error in multiplication of array by a number

5 次查看(过去 30 天)
Hello, I have a question, I have array X that has 3352 numbers in it and i am trying to multiply every number by 3017.4. And its not going well.
These are the last 2 numbers of array 0.2204 0.1897. After I write x1=x*3017.4 it returns new array x1 and in it the last 2 numbers look like this 0.6650 0.5723.
And I dont get why it is doing this, and it is happening to all numbers in that array, I even tried to multiply by 1000 and 3 in kinda works but not completely. If I multiply it by 1000 it calculates correctly those last numbers 220.3920 189.6600 but then i multiply it by 3 it jumps back to 0.6650 0.5723.
I really want to know how to multiply it please help me, if thats my mistake or some matlab smart thingie.
  6 个评论
Bruno Luong
Bruno Luong 2020-7-28
编辑:Bruno Luong 2020-7-28
Look at the exponent displayed on top of the result when you display the result.
>> a=rand(1,10)
a =
0.0975 0.2785 0.5469 0.9575 0.9649 0.1576 0.9706 0.9572 0.4854 0.8003
>> a*1e6
ans =
1.0e+05 * % <====== THIS THING, is a common exponent of on numbers bellow
0.9754 2.7850 5.4688 9.5751 9.6489 1.5761 9.7059 9.5717 4.8538 8.0028
>>
Martin Kavka
Martin Kavka 2020-7-28
编辑:James Tursa 2020-7-28
my data is so long that i cant even see the beginning, but I have been looking for this but didint see it so I asked here we when i plotted it those numbers are in thousands so thanks a lot guys, love you

请先登录,再进行评论。

回答(1 个)

the cyclist
the cyclist 2020-7-28
Just a guess here. If you have
x = [0.2204 0.1897]
and then type
1000*x
in the command window, it will display [220.4 189.7], but it does not change the value of x. So, if you were to now do
3*x
you will get [0.6612 0.5691].
If you wanted to multiply x by 1000, you need
x = 1000*x
  5 个评论
the cyclist
the cyclist 2020-7-28
Oh, I just noticed Bruno mentioned the same thing in a comment above. I will still take credit for independent discovery. :-)
Bruno Luong
Bruno Luong 2020-7-28
No problem I give you all credit you want Mr cyclist.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by