이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hey everyone,
I have a quick question. I am trying to convert date strings from an excel spreadsheet into MATLAB. For example, lets say I have the following:
A1 1/1/2000 12:00 %mm\dd\yyyy hh:mm
A2 1/2/2000 12:05
A3 1/3/2000 12:08
B1 5
B2 6
B3 8
How can I plot the numerical data in column B as the y axis and the date strings as the x axis? I know I use xlsread. I have something like:
[excelDates, Test] = xlsread('date.xlsx');
I know its a relatively simple question, but any help would be greatly appreciated (:
~Sarah~
채택된 답변
Fangjun Jiang
2011년 10월 5일
What value do you get in excelDates after running that xlsread() command? You can plot the data directly and then use datetick('x').
[Value, Time] = xlsread('test.xls')
Time=datenum(Time);
plot(Time,Value);
datetick('x',0,'keepticks');
댓글 수: 10
Hey! I get no value for excelDates, but the variable Test gets all of the string values.
You should make the B column format as number so the numeric data can be read using xlsread(). [Num, Txt, Raw]=xlsread(). See update in answer.
Hmmm, I tried that, but then I got this error:
??? Error using ==> plot
Vectors must be the same lengths.
You need to check your Excel file. To test out the datetick() part of the code, use the example data:
Value=[5 6 8];
Time={'1/1/2000 12:00','1/2/2000 12:05','1/3/2000 12:08'};
Time=datenum(Time);
plot(Time,Value);
datetick('x',0,'keepticks');
So based on my understanding, this is what I have:
clc;
%****************EXCEL SPREADSHEET******************%
Column A
A1: 1-28-2010 20:40
A2: 1-28-2010 20:42
A3: 1-28-2010 20:44
Column B
B1: 5
B2: 7
B3: 3
%******************************************
%********MATLAB CODE*********%
[Data, Time] = xlsread('date.xlsx');
Time=datenum(Time);
plot(Time,Data);
datetick('x',0,'keepticks');
By the way the xlsread function is set up, it returns two outputs: a numeric array (data) and a cell array (Time). The cell array is for strings.
Then, I can use datenum to convert the cell array into a numerical array? and then plot?
I am still getting the same error that I mentioned before. Is it because I am not properly converting my cell array into numerical data?
I suspect you might have some cells in column A or B that contain blank white space. After running [Data, Time] = xlsread('date.xlsx'), check the value of Data and Time in Command Window. Do they have the same size? In you case, it should be 3x1.
Yeah, I am getting an error because of that:
whos Time results in a 5x1 double
whos Data results in a 0x0 double
Not too sure why...
Sorry I meant whos Time results in 3x1 double
Delete all the cells below the third row, even though they look empty. Some cells may contain whitespace.
You were right! :O I deleted the empty cells, and I guess some of it had white space because they work after deleting! Thanks so much!!
I asked everything on a "conceptual level" so I could understand the basics. Now I will apply it to my real problem. Thanks again (:
Now
추가 답변 (0개)
카테고리
도움말 센터 및 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)
