You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to read header (text data of 100000 rows,18 columns) from data in excel into Matlab using different directory
1 view (last 30 days)
Show older comments
How to read header (text data of 100000 rows,18 columns) from data in excel into Matlab using different directory
Accepted Answer
Fangjun Jiang
on 9 May 2018
Not sure what do you mean by "using different directory", but did you try?
[Num, Txt, Raw]=xlsread('C:\MyDirectory\MyExcel.xls');
19 Comments
Gali Musa
on 9 May 2018
I have imported the excel data but there is no header name and the header will be use for the performance calculation
Gali Musa
on 9 May 2018
i still have an issue when trying to do some calculation. My algorithm doesn't recognise the column header so as to pick and do some calculation.
Fangjun Jiang
on 9 May 2018
You need to clarify your question. An simple example might be helpful. You might want to consider readtable(). See "doc readtabel". There is an example reading from Spreadsheet with Header created in the table.
Gali Musa
on 9 May 2018
Edited: Walter Roberson
on 9 May 2018
suppose this is the data want to read from excel and make this calculations in the Matlab
headers = {'time','power','T1','RH','P1','T2'};
Data = [5 10 15 20 25 30 35 40 45; 20 21 23 21 22 23 21 22 23; 200 202 205 207 206 205 201 202 208; 83 80 82 81 82 83 81 82 80; 101 101 102 103 105 104 102 101 100; 400 401 403 405 401 407 406 402 406];
a = power + T1;
b = P1 + T2;
c = RH + P1 + T2;
Walter Roberson
on 9 May 2018
Do you mean that you have a .xls or .xlsx file that looks like
time power T1 RH P1 T2
____ _____ ___ __ ___ ___
5 20 200 83 101 400
10 21 202 80 101 401
15 23 205 82 102 403
20 21 207 81 103 405
25 22 206 82 105 401
30 23 205 83 104 407
35 21 201 81 102 406
40 22 202 82 101 402
45 23 208 80 100 406
Gali Musa
on 9 May 2018
Yes it has 19 columns names and 56000 rows name for the time of the days in a year. Please see a sample attached
Gali Musa
on 11 May 2018
Edited: Gali Musa
on 11 May 2018
Using T=readtable syntax is very slow. my challenges is i have date/time column on the data and Matlab recognises it as string and i tried to convert it to a number before using the [Num, Txt, Raw]=xlsread syntax having difficulty... i need to have column for time in the Num ... any help please
Walter Roberson
on 12 May 2018
Is it a text file or a .xls or .xlsx file? Are you using MS Windows with Excel installed? Could you attach a small sample? And which MATLAB release are you using?
Gali Musa
on 12 May 2018
Please see attached sample for the xlsx file. It does remove column for the date/time in NUm and i want it to be there because it uses wrong columns for the calculations due to the absence of the column. Thank you
Walter Roberson
on 12 May 2018
"and Matlab recognises it as string"
For this purpose it is important that we know whether you are using MS Windows with Excel installed, and that we know which MATLAB version you are using. We also need a sample as xlsx not csv.
We need this information between there are multiple ways of encoding date/time information in Excel, and for some of them the result you will get in MATLAB depends upon which MATLAB version you are using and whether you are using MS Windows with Excel installed. Things that export as text dates are not necessarily stored as text.
Walter Roberson
on 12 May 2018
I checked inside the xlsx and find that the dates and times there are represented as excel numeric date format. readtable() would convert those to datetime objects by default.
If you find that xlsread() is faster for you than readtable, then you could try
Num = xlsread('Test1.xlsx', 1, '', 'basic')
Basic mode would use built in functions instead of talking to Excel, and would force the dates to be left numeric. The resulting numeric column would be in Excel date numbering format, such as 42208.5034722222 for 23-Jul-2015 12:05:00 . The easiest way to convert those to useable times would be
d = datetime(Num(:,1), 'ConvertFrom', 'Excel');
Walter Roberson
on 13 May 2018
The magic way to force xlsread() to return a number for excel dates is to use 'basic' mode. If that is too slow for you, then fix your code so that it no longer expects to date to be a column in what is returned from the num output of xlsread.
For example you could change your code to use the raw output of xlsread(), so that you have all of the row numbering that you expect. Sample code:
[~, ~, raw] = xlsread('Test1.xlsx');
raw(1,:) = []; %remove header
if ischar(raw{1,1}) %dates are string
dates = datenum(raw(:,1));
raw(1,:) = num2cell(dates);
end
num = cell2mat(raw);
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)