Solved

Importing data from txt or Excel file in Matlab

Posted on 2009-07-12
10
2,168 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
  • 5
  • 4
10 Comments
 
LVL 9

Expert Comment

by:masheik
Comment Utility
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
Comment Utility
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
Comment Utility
i dont have matlab to check . can you show the output?
0
 

Author Comment

by:bose3
Comment Utility
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
Comment Utility
this link can help you,
go to remarks and Handling Excel date values
http://matlab.izmiran.ru/help/techdoc/ref/xlsread.html
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:bose3
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Awesome. Good work
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Hibernate methods 2 58
FizzBuzz challenge 9 71
java constructor error 8 86
Problem to event 3 48
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 tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now