Perform conditional operations on column of doubles
Afficher commentaires plus anciens
My preferred method to solving this problem would be an if or for argument measuring the length doubles within a column and performing either *10^-5 or *10^-4 depending on the result.
What I've done so far in this code is read a timestamp that is a serial date, converted it into a string, split the string at the decimal, split the date portion and time portion into separate columns. Now, I need to convert those numbers (doubles) into comparable formats for date and time that I have in another array. The format of that array is Date= 7, 8, 9 or 10 and time= 0.69123 (traditional day number for date and serial time for time). This is what I have so far:
data_compiled= compiled_data_import('data compiled.csv');
timestamps= cellfun(@(x) num2str(x,15),data_compiled(2:76944,1),'UniformOutput', false);
dateandtime= cellfun(@(x) strsplit(x,'.'),timestamps,'UniformOutput', false);
date_time= str2double(vertcat(dateandtime{:}));
date= date_time(:,1)-42185;
time= date_time(:,2)*10^-5;
the intermittent outputs look something like this:
timestamps= 42192.6192700
dateandtime= <42192,6192700>
date_time= 42192 6192700
date= 7
time= 0.61927
The problem arises when the time portion of the time stamp has precision<5. This causes the string to be shorter when I use num2str, and therefore 1 order off when I use str2double. My preferred method to solving this problem would be an if or for argument measuring the length of the double and performing either *10^-5 or *10^-4
Réponses (1)
Walter Roberson
le 20 Fév 2016
You can specify a format string for num2str instead of a number of digits. For example,
num2str(x, '%.15f')
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!