Read excel data but keep formatting? Is this possible?

7 views (last 30 days)
I have a huge excel data file of data collected every second and the time column is in the format 12:12:56, But when i do an xlsread I do not get the same string. Is there a way to import this properly?

Answers (2)

Sara
Sara on 6 May 2014
Use this form of xlsread, you'll find your variable into txt or raw:
[num,txt,raw] = xlsread(___)
From the help: [num,txt,raw] = xlsread(_) additionally returns the text fields in cell array txt, and the unprocessed data (numbers and text) in cell array raw using any of the input arguments in the previous syntaxes. If xlRange is specified, leading blank rows and columns in the worksheet that precede rows and columns with data are returned in raw.
  25 Comments
Sara
Sara on 8 May 2014
Jose meant that you can use activex in matlab. that's a way to do it too, but I have never used it to read from excel, only to write. you may want to look into it anyway.
matlabuser12
matlabuser12 on 20 May 2014
That's what I would do:
Search for the string time (to know when start reading data)
While reading, check that suddenly there is no empty cell or char
do not stop (as the code does now) but rather keep going until you find "time" again
repeat
I would use a while loop and read a max of 500 lines with no numeric data, so that you have a way to stop the code when you actually reach the end of file. I suppose none would use a header of 500 lines! Take a shot at it, in case you can post again if you go nowhere :) As for the code, it's for you to modify as you please.
I am struggling to do this, where in the code does this go?

Sign in to comment.


matlabuser12
matlabuser12 on 20 May 2014
I am struggling to do this:
That's what I would do:
Search for the string time (to know when start reading data)
While reading, check that suddenly there is no empty cell or char
do not stop (as the code does now) but rather keep going until you find "time" again
repeat
I would use a while loop and read a max of 500 lines with no numeric data, so that you have a way to stop the code when you actually reach the end of file. I suppose none would use a header of 500 lines! Take a shot at it, in case you can post again if you go nowhere :) As for the code, it's for you to modify as you please.
Where in the code does this go?
  2 Comments
Sara
Sara on 20 May 2014
Can you attach a draft of the code you are using? I suppose you started modifying things.
matlabuser12
matlabuser12 on 20 May 2014
I haven't really modified the mainddd you posted earlier much at all.Tried to incorporate a find after the n = find(~cellfun(@isempty,strfind(header,str))==1,1); line but am not sure that is the right place for this.
Since then been stuck at trying to convert the inputted timespan to seconds since I was just told that the graph needs to have 0-6hrs on the X axis in seconds. The way that the person currently does this is have a data column of [1:.0003:6] and they just plot against that every time. They are using excel though so that means it doesnt matter if the X-Y data size doesnt match but in matlab if the user selects a time span that is not equal to that many seconds it will never plot and just crash.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!