Multiplying By 10000 vs 10^4

7 次查看(过去 30 天)
Harel Harel Shattenstein
编辑: Stephan 2018-4-27
Why
A=rand(3,3);
B=A(:)*10000;
is different from
A=rand(3,3);
B=A(:)*10^4;
  2 个评论
Stephan
Stephan 2018-4-27
Hi,
it isnt:
>> A = rand(3,3)
A =
0.8147 0.9134 0.2785
0.9058 0.6324 0.5469
0.1270 0.0975 0.9575
>> B= A(:)*10000
B =
1.0e+03 *
8.1472
9.0579
1.2699
9.1338
6.3236
0.9754
2.7850
5.4688
9.5751
>> C = A(:)*10^4
C =
1.0e+03 *
8.1472
9.0579
1.2699
9.1338
6.3236
0.9754
2.7850
5.4688
9.5751
>> Yes_it_is_the_same = B == C
Yes_it_is_the_same =
9×1 logical array
1
1
1
1
1
1
1
1
1
Stephan
Stephan 2018-4-27
编辑:Stephan 2018-4-27
the way you wrote it, will generate a new matrix A with new random numbers, which will most likely not be the same as in the first run:
>> clear all
>> A = rand(3,3)
A =
0.9649 0.9572 0.1419
0.1576 0.4854 0.4218
0.9706 0.8003 0.9157
>> B= A(:)*10000
B =
1.0e+03 *
9.6489
1.5761
9.7059
9.5717
4.8538
8.0028
1.4189
4.2176
9.1574
>> A = rand(3,3)
A =
0.7922 0.0357 0.6787
0.9595 0.8491 0.7577
0.6557 0.9340 0.7431
>> C = A(:)*10^4
C =
1.0e+03 *
7.9221
9.5949
6.5574
0.3571
8.4913
9.3399
6.7874
7.5774
7.4313
>> Yes_it_is_the_same = B == C
Yes_it_is_the_same =
9×1 logical array
0
0
0
0
0
0
0
0
0
So you understand the difference between both versions?
bets regards

请先登录,再进行评论。

回答(1 个)

Stephan
Stephan 2018-4-27
See comments, when working with random numbers you have to understand, that everytime you use the command new random numbers will appear - thats the reason why you get different values for the supposed same thing.
Best regards
Stephan

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by