After I export my data to Excel my some of my decimal values converted to date format by Excel. For example, my decimal data was 1.25 but it seems Jan.25 in Excel. How can I re-convert to correct decimal format ?
When you import the data set the column data type specifically to number.
Without sample data (both input and resulting Excel values) it is hard to diagnose the problem.
Related
I am working on a datasets in Excel in which I have a column named Duration containing values such as 11:01, 01:39:13 etc. The format here is either hh:mm:ss or mm:ss. How can I do operations such as addition & subtraction on such values?
The file is of XLSX format & I am working on the latest version of Office.
Most likely your "times" are actually text that look like times. They will need to be converted to actual times to be summed.
The issue is that if one does a straight conversion on 11:01 Excel will assume hh:mm not mm:ss
So we need to add some parsing to get the correct time format then sum the results:
=SUMPRODUCT(--RIGHT("00:"&B2:B4,8))
I've imported an Excel spreadsheet into MATLAB which contains a column of timestamps I would like to extract. However, as Excel stores timestamps as numerical data, the imported cells are now in a non-string format such as 0.4479, 0.4480 etc. Is there a quick way to convert all cells to a HH:MM:SS format?
Yep, datestr can handle this pretty easily.
Given:
numericCellData = {0.4479 0.4480}
Use:
datestr(cell2mat(numericCellData),'HH:MM:SS')
What we are doing:
Use the cell2mat function to convert your cell array to a more typical numeric array. This is what the workhorse datestr expects.
The datestr function is meant to perform this exact type of conversion, from numeric time to a string representation.
Your examples were an interesting specific case, where your values probably represented only time (all values were less than 1; you asked for HH:MM:SS format). For the more general case, of converting numeric date-and-time data from Excel to Matlab, you will usually need to adjust for the date offset used:
Matlab date numbers: Are in units of days, usually double precision, and the 0 value represents January 0, 0000. (Think, new years eve in an era when the Roman empire was the dominant political entity in Europe, as represented by the Gregorian calendar which had not yet been developed.)
Excel date numbers: Are also in units of days. However the number 0 represents January 0, 1900. (Or, new years eve, 1899). This is 693961 in the Matlab system, and sometimes you need to make the adjustment.
Select the Column > Right Click >Format Cells >Number Tab> Select Time under Category > Select the Type and click on Ok
I'm trying to import an excel file containing latitude and longitude data into MATLAB. I'm using the 'Import Data' option. It is reading the latitude and longitude information just fine except that some of the longitude cells are being marked as unimportable and being replaced by NaN. They contain values like -119.253 etc. What could be the reason for this? I just want to keep the original information.
Below is a snapshot of a portion of my Excel spreadsheet:
The screenshot shows the Problem. All numbers that are left-alligned aren't real numbers, that is text. Numbers are alligned to the right.
Mark the column in excel and change the format to number.
As you might have come accross, MS Excel tends to convert times to decimal values. I do want it to convert the values automatically because I need the time value. Suppose I have following data:
Departure | Time
Istanbul 06:45
Ankara 01:30
I am using Concatenate function to create a desired string as Istanbul: 08:00 and Ankara: 18:30. However, when I use the formula, Excel converts hours to decimals and I get Istanbul: 0.28125 and Ankara: 0.0625. I do not want it to convert. How can I do this?
ps: This also happens when I copy time values from Excel to Notepad++. Moreover, when I import time values into PostgreSQL through add-in, I still get decimal values in the columns
You want to use the TEXT function to convert the time into the text format that you require. Something like this:
=CONCATENATE("Istanbul: ", TEXT(A1,"hh:mm"), " and Ankara: "18:30, TEXT(A2,"hh:mm"))
I'm trying to import data from excel into matlab where the data contains a column of time where time is in the format of 00:05, 22:00 etc...
Is there a way of importing this into matlab without changing the format?
Currently, when importing the vector into matlab, it changes the values to decimals which is not what I need.
Have you tried to convert the numbers you've got from Excel file with DATESTR function?
xtimestr = datestr(xtime,'HH:MM');
This should have no problems with time. But you have to take care if you are getting dates as well, because of different date systems used by MATLAB and Excel. See When to Convert Dates from Excel Files for more details.