convert date to datenum import from excel

조회 수: 4 (최근 30일)
ErikJ
ErikJ 2018년 7월 17일
댓글: ErikJ 2018년 7월 19일
hello
I want to import a simple excel file to matlab and convert the column with dates from text to numeric values. The problem is that the rule convert does not show up as an alternativ. I can only replace things. Would be very glad if someone could help.

채택된 답변

Adam Danz
Adam Danz 2018년 7월 17일
편집: Adam Danz 2018년 7월 17일
I agree that readtable() is the better option but if you decide to stick with the import tool, here's an idea.
In the dropdown menu under your variable name 'dag' where it currently says "Number" in your screenshot, select a date and time option. This will convert your timestamps to datetime format. After importing, you can use datenum() to convert them to double if desired.
Here's a screen shot with a different data set.
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 7월 17일
When you click to generate, it should have created importfile.m
Adam Danz
Adam Danz 2018년 7월 17일
Yeah, that might be the problem. After you select datetime you'll need to re-generate the importfile() function so the new version accounts for the new format.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2018년 7월 17일
We recommend using readtable() instead. With new enough MATLAB, it can help to use detectImportOptions() with readtable()

ErikJ
ErikJ 2018년 7월 19일
I solved the problem now. Thanks! Now when I have imported the data I calculate new values based on the old. Now I would very much like to add this new values as a new row (=one new value per column) and save this in the excel file (overwrite) without changing the formatting. How can i do this?
Thanks in advance
Erik
  댓글 수: 4
Adam Danz
Adam Danz 2018년 7월 19일
편집: Adam Danz 2018년 7월 19일
doc xlswrite()
Read about the inputs and how to use this function. There's even an example that shows you how to insert data into specific cells of the spreadsheet. I was about to type up a quick demo but Matlab's documentation covers it. The best way to learn is by digging into the documentation. If you get stuck, come back.
It would be wise to make a copy of your data as you poke around with this function in case you accidentally overwrite your data.
ErikJ
ErikJ 2018년 7월 19일
Ok thanks. I'll read about xlswrite()

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by