0

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 
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Apologies for being thick but I'm not sure I understand how the first set of numbers links to the decimal numbers. What is the relation? – kkuilla Jan 20 '15 at 10:31
  • the first set of number is index, the second is the real value in single format.They are store currently in cell format which is no problem. But I want to get part of the value based on the index, so I converte it to mat format...Then from here I want to put them in one matrix with 2 columns...here is the problem..it becomes the third parts number..so all the value behind dot are cut away...Do you understand ? – user2307344 Jan 20 '15 at 10:48

1 Answers1

0

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.

A. Donda
  • 8,381
  • 2
  • 20
  • 49
  • Thanks...but then my index will be not so accuracy any more..moreover, if I can store them in cell, how can I plot them? it is a 30 X 2 cell..thanks again – user2307344 Jan 21 '15 at 08:17
  • @user2307344, the question is, why do you need them in the same array anyway? Just keep two variables for the two types of data, one of type int64 and the other of type double. `plot` needs separate arguments for x- and y-axis anyway. – A. Donda Jan 21 '15 at 13:49
  • But even with one double array, your indices will still be accurate. Remember that what is printed on screen is not the full internal representation. According to [Wikipedia](https://en.wikipedia.org/wiki/Double-precision_floating-point_format), double has 15–17 decimal digits precision. Your indices have 9 decimal digits, so you are well on the safe side here. – A. Donda Jan 21 '15 at 13:50
  • As a third variant, you can have a cell array with 2 entries, the first of which is a int64 array of your indices and the second is a double array of the other numbers. – A. Donda Jan 21 '15 at 13:54
  • 1
    Thanks so much @ A. Donda . I did it as you said in the beginning, with double ...so it works fine now... – user2307344 Jan 22 '15 at 07:29