Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Importing data from txt or Excel file in Matlab

Posted on 2009-07-12
10
Medium Priority
?
2,289 Views
Last Modified: 2016-02-10
Hi,
I am trying to import data into Matlab. There are five columns: Date, Time, Open, High, Low, Last Price. I am trying to do this through "uiimport" (import wizard) or "xlsread" command. The problem is that Matlab reads the Date and Time column as "Textdata" even though the data is in Date/Time format. How can I convert the data into Date/Time within Matlab? I have attached a sample txt file. Please advise. Thanks in advance
gbp-samp.txt
0
Comment
Question by:bose3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 9

Expert Comment

by:masheik
ID: 24838473
hi bose,
%read and display excel data
[data, textString] = xlsread('gbp-samp.xls');

here data represents only numeric data,and textString represents only strings in cell array

make sure that  the data is on  correct sheet number .If it is not please mention the sheet number like this,
[data, textString] = xlsread('gbp-samp.xls','sheetName');

for more information on xlsread refer here,

http://www.sgr.nada.kth.se/unix/software/matlab/Release_14.1/techdoc/ref/xlsread.html
0
 

Author Comment

by:bose3
ID: 24838629
The data is in a correct tab since there is only one tab in the whole spreadsheet. I have attached  the Excel file sample aslo.
gbp-samp.xlsx
0
 
LVL 9

Expert Comment

by:masheik
ID: 24838750
i dont have matlab to check . can you show the output?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:bose3
ID: 24838819
I have posted two pics, one for the text data and the other is for numeric data. see attachment

numeric-data.PNG
text-data.PNG
0
 
LVL 9

Expert Comment

by:masheik
ID: 24838834
this link can help you,
go to remarks and Handling Excel date values
http://matlab.izmiran.ru/help/techdoc/ref/xlsread.html
0
 

Author Comment

by:bose3
ID: 24843477
I tried using ths script but no luck yet
[num, txt]=xlsread(GBP.xls);
tday1=txt(2:end, 1);
datestr(datenum(tday1, mm/dd/yyyy), mm/dd/yy);
tday1=str2double(cellstr(tday1));
0
 
LVL 9

Expert Comment

by:masheik
ID: 24846587
as i already mentioned, i do not have matlab to check
can you check this out,
[xlsDates] = xlsread('test.xls','A2:A21');
mDates = datenum('30-Dec-1899') + xlsDates;
datestr(mDates,2)
0
 

Author Comment

by:bose3
ID: 24851798
No luck with your script but I managed to find this http://www.mathworks.com/matlabcentral/fileexchange/18430. It seperates MM DD YYYY in seperate columns and keep them as numeric. Is there a way to join the columns after a split?
0
 
LVL 15

Accepted Solution

by:
yuk99 earned 200 total points
ID: 24853137
Try the code below and check D structure.
D=importdata('gbp-samp.txt');
D.date = datenum(cell2mat([D.textdata(2:end,1) repmat({' '},size(D.data,1),1) D.textdata(2:end,2)]));
D.datestr = datestr(D.date,0);
D = rmfield(D,'textdata');

Open in new window

0
 

Author Closing Comment

by:bose3
ID: 31602589
Awesome. Good work
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question