How to convert a table of doubles to matrix?
4 ビュー (過去 30 日間)
古いコメントを表示
Hi I have a 2 dimensional table that is made up of numbers and NaNs. I want to convert this table to a matrix so that I can subtract across columns. A way in either direction can help:
1) How to convert a table to matrix, given that the table has values of only doubles and NaNs.
2) How to subtract a values inside a table that are just numbers.
Thank you so much!
5 件のコメント
dpb
2019 年 9 月 28 日
We still don't know the answer to the question posed of what the structure of the table is...we need a sample of the table to see...
I'll take a stab at a guess with a sample, though...here's a small table I built earlier today for a totally unrelated NG Q?
>> t
t =
14×6 table
Date Month Cost Therms Rate NGPrice
__________ ___________ _____ ______ _______ _______
09/20/2019 'September' 17.99 9.5 0.52807 NaN
08/20/2019 'August' 14.72 6.2 0.4212 NaN
07/22/2019 'July' 16.11 7.6 0.47176 NaN
06/19/2019 'June' 7.54 11 1.4589 15.67
05/20/2019 'May' 26.87 18.5 0.6885 12.84
04/19/2019 'April' 68.39 54.9 0.80275 10.92
03/21/2019 'March' 73.74 77.1 1.0456 9.48
02/20/2019 'February' 63.42 64.7 1.0202 9.47
01/23/2019 'January' 74.28 57.8 0.77814 9.43
12/19/2018 'December' 54.6 40.4 0.73993 9.63
11/16/2018 'November' 29.79 21.5 0.72172 9.43
10/19/2018 'October' 20.7 12.1 0.58454 12.26
09/19/2018 'September' 16.19 7.6 0.46943 17.31
08/20/2018 'August' 13.98 5.4 0.38627 18.63
>>
If for some reason we wanted the difference across those last four numeric columns, then
>> t.Diff=diff(t{:,3:6},[],2)
t =
14×7 table
Date Month Cost Therms Rate NGPrice Diff
__________ ___________ _____ ______ _______ _______ ____________________________
09/20/2019 'September' 17.99 9.5 0.52807 NaN -8.49 -8.9719 NaN
08/20/2019 'August' 14.72 6.2 0.4212 NaN -8.52 -5.7788 NaN
07/22/2019 'July' 16.11 7.6 0.47176 NaN -8.51 -7.1282 NaN
06/19/2019 'June' 7.54 11 1.4589 15.67 3.46 -9.5411 14.211
05/20/2019 'May' 26.87 18.5 0.6885 12.84 -8.37 -17.811 12.151
04/19/2019 'April' 68.39 54.9 0.80275 10.92 -13.49 -54.097 10.117
03/21/2019 'March' 73.74 77.1 1.0456 9.48 3.36 -76.054 8.4344
02/20/2019 'February' 63.42 64.7 1.0202 9.47 1.28 -63.68 8.4498
01/23/2019 'January' 74.28 57.8 0.77814 9.43 -16.48 -57.022 8.6519
12/19/2018 'December' 54.6 40.4 0.73993 9.63 -14.2 -39.66 8.8901
11/16/2018 'November' 29.79 21.5 0.72172 9.43 -8.29 -20.778 8.7083
10/19/2018 'October' 20.7 12.1 0.58454 12.26 -8.6 -11.515 11.675
09/19/2018 'September' 16.19 7.6 0.46943 17.31 -8.59 -7.1306 16.841
08/20/2018 'August' 13.98 5.4 0.38627 18.63 -8.58 -5.0137 18.244
>>
does it. See the documentation for the table class for an exposition how to address and retrieve data from a table. Much like cell arrays, the "curlies" {} are used to dereference the data and return in native format rather than as another table object.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!