Result of combining multiple matrices turns into int32

2 ビュー (過去 30 日間)
Stijn
Stijn 2014 年 11 月 14 日
コメント済み: Stijn 2014 年 11 月 18 日
I have several matrices, which I want to combine into one big matrix:
robotnumber =
1
2
3
4
orientation =
-0.0002
179.9671
0.0020
179.9953
detection =
1 782
1 782
1 782
1 782
detdistance =
0.1533
0.1483
0.1569
0.1647
spacer =
0 0 0
0 0 0
0 0 0
0 0 0
distance =
0 2.1629 0.9540 3.8822
2.1629 0 1.5346 2.1488
0.9540 1.5346 0 3.5705
3.8822 2.1488 3.5705 0
But, if I try the following code:
Robotinfo = [robotnumber,orientation,detection,detdistance,speed,spacer,distance];
All the data goes, apparently, through an int32 function, resulting in:
Robotinfo =
The workspace also says: Robotinfo 4x14 int32, instead of Robotinfo 4x14 single.
Does anyone know what causes this problem?
Thanks!

採用された回答

Guillaume
Guillaume 2014 年 11 月 14 日
編集済み: Guillaume 2014 年 11 月 14 日
Most likely one of your variable is int32. As a result, all the other variables are implicitly converted to int32. Convert it to double before concatenating it.
concat = [dblvar, dblvar, double(int32var)];
rant: Most languages have made the sensible decision that implicit conversions are widening. That is, an implicit conversion will only happen if there is no loss of data (e.g. int8 -> int32, float->double or int->double). Matlab, on the other hand has narrowing conversions. An int32 will get demoted to an int8 with all the loss of data that ensues. Same with double->float or as in your case double->int. Completely absurd!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by