Solved

Importing data from txt or Excel file in Matlab

Posted on 2009-07-12
10
2,259 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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 50 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 Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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 tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

717 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