이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to read header (text data of 100000 rows,18 columns) from data in excel into Matlab using different directory
조회 수: 1 (최근 30일)
이전 댓글 표시
How to read header (text data of 100000 rows,18 columns) from data in excel into Matlab using different directory
채택된 답변
Fangjun Jiang
2018년 5월 9일
Not sure what do you mean by "using different directory", but did you try?
[Num, Txt, Raw]=xlsread('C:\MyDirectory\MyExcel.xls');
댓글 수: 19
Gali Musa
2018년 5월 9일
I have imported the excel data but there is no header name and the header will be use for the performance calculation
Gali Musa
2018년 5월 9일
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
2018년 5월 9일
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
2018년 5월 9일
편집: Walter Roberson
2018년 5월 9일
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
2018년 5월 9일
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
2018년 5월 9일
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
2018년 5월 11일
편집: Gali Musa
2018년 5월 11일
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
2018년 5월 12일
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
2018년 5월 12일
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
2018년 5월 12일
"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
2018년 5월 12일
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
2018년 5월 13일
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);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)