Search code examples
matlabint64

Matlab multiple type numbers in same table


I want to put those two types of number inside one table. One column with index int64 and another column with value single....

1359410513
1359410521
1359410529
1359410536
1359410542   
1359410548
1359410554

40.299999
39.099998
37.900002
36.799999
35.700001
34.700001
33.599998

But when I put them in one the value says is: 2000 X 2 int64. So all the values are cut away after dot. like this:

40
39
38
37
36
35
34

Can anyone help me with this? how to put them in one table. Thanks

Here is one example code...so basic idea is when one column is int64, the other is single. the result always converte one of them into the same type and the result lose resolution:

value1=int64(sort((1359418241-20)*rand(30,1)+20,'ascend'));
value2=single(rand(30,1));
field1='index';
field2='value';
s=struct(field1,value1,field2,value2)

data_table=struct2table(s);
data_cell=table2cell(data_table);
data_mat = cell2mat(data_cell(:, 1));
data_mat1 = cell2mat(data_cell(:, 2));

start_time=701146404;
end_time=1221278149;
%Find the neighbour points
thresholdpoint_start = find(data_mat > start_time, 1)-1;
thresholdpoint_end = find(data_mat >= end_time, 1);
for i=1:thresholdpoint_end-thresholdpoint_start+1 
    data_ss(i,2)=single(data_mat1(thresholdpoint_start+i-1,1));
    data_ss(i,1)=data_mat(thresholdpoint_start+i-1,1);


end 

Solution

  • The correct structure for data with different data types is the cell array. There is no way to do the same with a standard array (matrix). What you can do however is to put all your data into a double array, which has enough precision to correctly represent your integers.