Histogram from a table data / or convert table data into numeric
58 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have a table of 1000*2 values,
and i am trying to make a histogram,
but its giving me error
Error using histogram
Expected input number 1, x, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical, datetime, duration, categorical
Instead its type was table.
0 0.957766000000000
0.00100000000000000 6.00000000000000e-06
0.00200000000000000 1.00000000000000e-06
0.00300000000000000 9.00000000000000e-06
0.00400000000000000 9.00000000000000e-06
0.00500000000000000 1.00000000000000e-05
0.00600000000000000 1.00000000000000e-05
0.00700000000000000 8.00000000000000e-06
0.00800000000000000 4.00000000000000e-06
0.00900000000000000 1.30000000000000e-05
0.0100000000000000 8.00000000000000e-06
0.0110000000000000 9.00000000000000e-06
0.0120000000000000 3.00000000000000e-06
0.0130000000000000 1.00000000000000e-05
0.0140000000000000 1.40000000000000e-05
0.0150000000000000 4.00000000000000e-06
0.0160000000000000 1.00000000000000e-05
0.0170000000000000 6.00000000000000e-06
0.0180000000000000 6.00000000000000e-06
0.0190000000000000 9.00000000000000e-06
0.0200000000000000 1.50000000000000e-05
0.0210000000000000 1.00000000000000e-05
0.0220000000000000 1.50000000000000e-05
0.0230000000000000 1.50000000000000e-05
0.0240000000000000 6.00000000000000e-06
0.0250000000000000 1.20000000000000e-05
0.0260000000000000 5.00000000000000e-06
0.0270000000000000 8.00000000000000e-06
0.0280000000000000 5.00000000000000e-06
0.0290000000000000 8.00000000000000e-06
0.0300000000000000 7.00000000000000e-06
0.0310000000000000 7.00000000000000e-06
0.0320000000000000 8.00000000000000e-06
0.0330000000000000 8.00000000000000e-06
0.0340000000000000 6.00000000000000e-06
0.0350000000000000 7.00000000000000e-06
0.0360000000000000 1.20000000000000e-05
0.0370000000000000 1.00000000000000e-05
0.0380000000000000 8.00000000000000e-06
0.0390000000000000 1.10000000000000e-05
0.0400000000000000 1.10000000000000e-05
0.0410000000000000 9.00000000000000e-06
0.0420000000000000 9.00000000000000e-06
0.0430000000000000 7.00000000000000e-06
0.0440000000000000 1.30000000000000e-05
0.0450000000000000 1.40000000000000e-05
0.0460000000000000 1.10000000000000e-05
0.0470000000000000 6.00000000000000e-06
0.0480000000000000 7.00000000000000e-06
0.0490000000000000 8.00000000000000e-06
0.0500000000000000 9.00000000000000e-06
0.0510000000000000 1.00000000000000e-05
0.0520000000000000 1.10000000000000e-05
0.0530000000000000 8.00000000000000e-06
0.0540000000000000 8.00000000000000e-06
0.0550000000000000 4.00000000000000e-06
0.0560000000000000 1.00000000000000e-05
0.0570000000000000 1.30000000000000e-05
0.0580000000000000 1.00000000000000e-05
0.0590000000000000 1.30000000000000e-05
0.0600000000000000 5.00000000000000e-06
0.0610000000000000 4.00000000000000e-06
0.0620000000000000 7.00000000000000e-06
0.0630000000000000 6.00000000000000e-06
0.0640000000000000 9.00000000000000e-06
0.0650000000000000 1.00000000000000e-05
0.0660000000000000 1.00000000000000e-05
0.0670000000000000 1.10000000000000e-05
0.0680000000000000 1.30000000000000e-05
0.0690000000000000 1.20000000000000e-05
0.0700000000000000 1.00000000000000e-05
0.0710000000000000 1.10000000000000e-05
0.0720000000000000 1.00000000000000e-05
0.0730000000000000 1.40000000000000e-05
0.0740000000000000 1.10000000000000e-05
0.0750000000000000 1.00000000000000e-05
0.0760000000000000 1.00000000000000e-05
0.0770000000000000 2.00000000000000e-05
0.0780000000000000 9.00000000000000e-06
0.0790000000000000 9.00000000000000e-06
0.0800000000000000 6.00000000000000e-06
0.0810000000000000 1.10000000000000e-05
0.0820000000000000 9.00000000000000e-06
0.0830000000000000 9.00000000000000e-06
0.0840000000000000 9.00000000000000e-06
0.0850000000000000 1.10000000000000e-05
0.0860000000000000 1.10000000000000e-05
0.0870000000000000 6.00000000000000e-06
0.0880000000000000 1.70000000000000e-05
0.0890000000000000 1.30000000000000e-05
0.0900000000000000 1.20000000000000e-05
0.0910000000000000 7.00000000000000e-06
0.0920000000000000 1.30000000000000e-05
0.0930000000000000 1.90000000000000e-05
0.0940000000000000 7.00000000000000e-06
0.0950000000000000 8.00000000000000e-06
0.0960000000000000 9.00000000000000e-06
0.0970000000000000 1.10000000000000e-05
0.0980000000000000 1.20000000000000e-05
0.0990000000000000 1.20000000000000e-05
0.100000000000000 1.20000000000000e-05
0.101000000000000 1.10000000000000e-05
0.102000000000000 1.60000000000000e-05
0.103000000000000 9.00000000000000e-06
0.104000000000000 1.20000000000000e-05
0.105000000000000 1.30000000000000e-05
0.106000000000000 7.00000000000000e-06
0.107000000000000 5.00000000000000e-06
0.108000000000000 9.00000000000000e-06
0.109000000000000 5.00000000000000e-06
0.110000000000000 8.00000000000000e-06
0.111000000000000 1.00000000000000e-05
0.112000000000000 1.20000000000000e-05
0.113000000000000 1.50000000000000e-05
0.114000000000000 4.00000000000000e-06
0.115000000000000 6.00000000000000e-06
0.116000000000000 1.10000000000000e-05
0.117000000000000 6.00000000000000e-06
0.118000000000000 5.00000000000000e-06
0.119000000000000 9.00000000000000e-06
0.120000000000000 8.00000000000000e-06
0.121000000000000 1.30000000000000e-05
0.122000000000000 7.00000000000000e-06
0.123000000000000 1.50000000000000e-05
0.124000000000000 1.40000000000000e-05
0.125000000000000 1.00000000000000e-05
0.126000000000000 1.10000000000000e-05
0.127000000000000 1.10000000000000e-05
0.128000000000000 1.60000000000000e-05
0.129000000000000 1.00000000000000e-05
0.130000000000000 8.00000000000000e-06
0.131000000000000 8.00000000000000e-06
0.132000000000000 1.00000000000000e-05
0.133000000000000 1.00000000000000e-05
0.134000000000000 8.00000000000000e-06
0.135000000000000 1.20000000000000e-05
0.136000000000000 1.00000000000000e-05
0.137000000000000 7.00000000000000e-06
0.138000000000000 9.00000000000000e-06
0.139000000000000 1.30000000000000e-05
0.140000000000000 1.40000000000000e-05
0.141000000000000 8.00000000000000e-06
0.142000000000000 9.00000000000000e-06
0.143000000000000 7.00000000000000e-06
0.144000000000000 1.00000000000000e-05
0.145000000000000 1.60000000000000e-05
0.146000000000000 1.20000000000000e-05
0.147000000000000 1.40000000000000e-05
0.148000000000000 1.30000000000000e-05
0.149000000000000 1.00000000000000e-05
0.150000000000000 8.00000000000000e-06
0.151000000000000 1.30000000000000e-05
0.152000000000000 1.60000000000000e-05
0.153000000000000 1.30000000000000e-05
0.154000000000000 9.00000000000000e-06
0.155000000000000 1.40000000000000e-05
0.156000000000000 1.20000000000000e-05
0.157000000000000 7.00000000000000e-06
0.158000000000000 1.20000000000000e-05
0.159000000000000 1.00000000000000e-05
0.160000000000000 1.50000000000000e-05
0.161000000000000 6.00000000000000e-06
0.162000000000000 1.30000000000000e-05
0.163000000000000 1.30000000000000e-05
0.164000000000000 1.20000000000000e-05
0.165000000000000 9.00000000000000e-06
0.166000000000000 9.00000000000000e-06
0.167000000000000 1.30000000000000e-05
0.168000000000000 1.60000000000000e-05
0.169000000000000 1.60000000000000e-05
0.170000000000000 1.40000000000000e-05
0.171000000000000 1.20000000000000e-05
0.172000000000000 1.50000000000000e-05
0.173000000000000 8.00000000000000e-06
0.174000000000000 1.10000000000000e-05
0.175000000000000 1.40000000000000e-05
0.176000000000000 1.20000000000000e-05
0.177000000000000 1.00000000000000e-05
0.178000000000000 8.00000000000000e-06
0.179000000000000 1.20000000000000e-05
0.180000000000000 1.30000000000000e-05
0.181000000000000 7.00000000000000e-06
0.182000000000000 9.00000000000000e-06
0.183000000000000 1.50000000000000e-05
0.184000000000000 1.30000000000000e-05
0.185000000000000 8.00000000000000e-06
0.186000000000000 1.30000000000000e-05
0.187000000000000 1.40000000000000e-05
0.188000000000000 1.60000000000000e-05
0.189000000000000 4.00000000000000e-06
0.190000000000000 1.00000000000000e-05
0.191000000000000 1.30000000000000e-05
0.192000000000000 8.00000000000000e-06
0.193000000000000 1.40000000000000e-05
0.194000000000000 1.10000000000000e-05
0.195000000000000 7.00000000000000e-06
0.196000000000000 8.00000000000000e-06
0.197000000000000 1.90000000000000e-05
0.198000000000000 1.10000000000000e-05
0.199000000000000 1.20000000000000e-05
0.200000000000000 1.30000000000000e-05
0.201000000000000 1.00000000000000e-05
0.202000000000000 1.00000000000000e-05
0.203000000000000 1.90000000000000e-05
0.204000000000000 8.00000000000000e-06
0.205000000000000 1.20000000000000e-05
0.206000000000000 1.00000000000000e-05
0.207000000000000 9.00000000000000e-06
0.208000000000000 7.00000000000000e-06
0.209000000000000 7.00000000000000e-06
0.210000000000000 1.70000000000000e-05
0.211000000000000 1.40000000000000e-05
0.212000000000000 8.00000000000000e-06
0.213000000000000 1.00000000000000e-05
0.214000000000000 8.00000000000000e-06
0.215000000000000 7.00000000000000e-06
0.216000000000000 1.80000000000000e-05
0.217000000000000 8.00000000000000e-06
0.218000000000000 1.10000000000000e-05
0.219000000000000 1.70000000000000e-05
0.220000000000000 1.70000000000000e-05
0.221000000000000 1.30000000000000e-05
0.222000000000000 1.00000000000000e-05
0.223000000000000 1.60000000000000e-05
0.224000000000000 7.00000000000000e-06
0.225000000000000 1.10000000000000e-05
0.226000000000000 1.20000000000000e-05
0.227000000000000 1.10000000000000e-05
0.228000000000000 7.00000000000000e-06
0.229000000000000 1.20000000000000e-05
0.230000000000000 1.70000000000000e-05
0.231000000000000 1.30000000000000e-05
0.232000000000000 4.00000000000000e-06
0.233000000000000 1.50000000000000e-05
0.234000000000000 7.00000000000000e-06
0.235000000000000 1.20000000000000e-05
0.236000000000000 1.70000000000000e-05
0.237000000000000 1.50000000000000e-05
0.238000000000000 1.10000000000000e-05
0.239000000000000 8.00000000000000e-06
0.240000000000000 1.50000000000000e-05
0.241000000000000 1.90000000000000e-05
0.242000000000000 8.00000000000000e-06
0.243000000000000 1.10000000000000e-05
0.244000000000000 1.20000000000000e-05
0.245000000000000 2.10000000000000e-05
0.246000000000000 1.10000000000000e-05
0.247000000000000 1.80000000000000e-05
0.248000000000000 1.20000000000000e-05
0.249000000000000 1.20000000000000e-05
0.250000000000000 1.40000000000000e-05
0.251000000000000 1.30000000000000e-05
0.252000000000000 9.00000000000000e-06
0.253000000000000 1.60000000000000e-05
0.254000000000000 1.00000000000000e-05
0.255000000000000 4.00000000000000e-06
Please help me thanks
2 件のコメント
Dyuman Joshi
2023 年 1 月 25 日
Show us your code.
The data is still in default format (double), just stored in form of a table. You need to access the Table columns properly.
Read - Access Data in a Table
Askic V
2023 年 1 月 25 日
Most probably, you will have to use table2array function at some point. Please have a look at the documentation:
https://www.mathworks.com/help/matlab/ref/table2array.html
回答 (1 件)
Suman Sahu
2023 年 3 月 9 日
Hi SANA,
The histogram function accepts a numerical array of types: double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical, datetime, duration, categorical as input argument, However, you are passing a table which results in an error. There are three ways by which you can handle this:
1. You can try to extract the column from the table you want to plot the histogram. However, in this approach you can only plot one column at a time.
%create an example table with two columns of random data
data table(randn(1000,1), randn(1000,1), 'VariableNames', {'Column1', 'Column2'});
% extract the first column as an array
x = data.Column1;
% create a histogram of the data
histogram(x);
2. You can extract part of the table as an array using table indexing as follows:
% create an example table with two columns of random data
table_data = table(randn(1000,1), randn(1000,1), 'VariableNames', {'Column1', 'Column2'});
% extract the required array
x = table_data{1:5, 2}; %this extracts the table’s rows 1 to 5 and column 2 which creates an array of dimension 5x1.
% create a histogram of the data
histogram(x);
3. You can convert the table to an array directly using the function table2array(table).
data_array = table2array(table_data);
histogram(data_array);
To learn more about the functions used above, refer to the following documentations:
- Histogram plot - MATLAB - MathWorks
- Convert table to homogeneous array - MATLAB table2array - MathWorks
- Table array with named variables that can contain different types - MATLAB - MathWorks
Hope this helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Histograms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!