What is a double matrix?

92 次查看(过去 30 天)
Zach Hanses
Zach Hanses 2021-12-11
评论: Awais Saeed 2021-12-11
I have data that I need to convert into a double matrix. How do I do that ?
  5 个评论
Zach Hanses
Zach Hanses 2021-12-11
I was told that using the double function will help in the process of getting the 5 year average for precipitation
Awais Saeed
Awais Saeed 2021-12-11
Decimal point data (aka floating pointer numbers) can be represented as either single precision numbers or double precesion numbers. Single precision data takes 32bits in memory while double precision data takes 64bits. The greater the number of bits, the higher the accuracy. But you can easy tell that double precision costs you more memory. Read more here.

请先登录,再进行评论。

回答(3 个)

KSSV
KSSV 2021-12-11
If it is a string, read about str2num, str2double.
If it is a single, use double.
If it is a sym class, use double.
  3 个评论
Zach Hanses
Zach Hanses 2021-12-11
double(precipitaiton) ?
KSSV
KSSV 2021-12-11
编辑:KSSV 2021-12-11
In MATLAB every variable has a class. You can get the class using the function class......the numbers i.e. floatingpoint numbers can be single or double. If your precipitation is a single, and you want it to double, yes use:
double(precipitaiton)

请先登录,再进行评论。


Awais Saeed
Awais Saeed 2021-12-11
A = magic(4) % data type is double
A = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
s = single(A) % convert double to single
s = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
d = double(s) % convert single to double
d = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
whos
Name Size Bytes Class Attributes A 4x4 128 double d 4x4 128 double s 4x4 64 single

Walter Roberson
Walter Roberson 2021-12-11
retime() works fine with single precision.
dates = datetime('2000-01-01') + calmonths(0:3:35).'
dates = 12×1 datetime array
01-Jan-2000 01-Apr-2000 01-Jul-2000 01-Oct-2000 01-Jan-2001 01-Apr-2001 01-Jul-2001 01-Oct-2001 01-Jan-2002 01-Apr-2002 01-Jul-2002 01-Oct-2002
data = randn(size(dates), 'single')
data = 12×1
-0.9242 -0.7978 -0.6076 -1.3254 -0.8482 1.1801 -1.7518 -1.1227 -0.5025 -1.3097
TT = timetable(dates, data)
TT = 12×1 timetable
dates data ___________ ________ 01-Jan-2000 -0.92422 01-Apr-2000 -0.79782 01-Jul-2000 -0.60761 01-Oct-2000 -1.3254 01-Jan-2001 -0.84822 01-Apr-2001 1.1801 01-Jul-2001 -1.7518 01-Oct-2001 -1.1227 01-Jan-2002 -0.50246 01-Apr-2002 -1.3097 01-Jul-2002 0.87082 01-Oct-2002 0.73953
TT5 = retime(TT, 'yearly', 'mean')
TT5 = 3×1 timetable
dates data ___________ _________ 01-Jan-2000 -0.91377 01-Jan-2001 -0.63564 01-Jan-2002 -0.050449

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by