Is it possible to configure data in a excel file from matlab? If so, How can I do it?
조회 수: 1 (최근 30일)
이전 댓글 표시
for example, I have an excel file with data in it, i would like to delete the first 5 rows in the first 14 columns.
Also instead of having:
2013 094 22:57:13 245387 5.002 0.006 4.992 0.001 -0.001 -0.005 7.99 5 2 0
I would like to have this in my excel file in every row:(notice i dont want the colons nor do i want the zero at the end):
2013 094 22 57 13 245387 5.002 0.006 4.992 0.001 -0.001 -0.005 7.99 5 2
How can I go about allowing matlab to do such modifications on an excel file and then save it.
thanks in advance,
Cordelle
댓글 수: 0
답변 (3개)
Evan
2013년 7월 29일
편집: Evan
2013년 7월 29일
Do you want the timestamp (22:57:13) to be split into separate rows or placed all in the same column?
Either way, a combination of xlsread and xlswrite, combined with some quick matrix modifications, will be all you'll need.
If you're not concerned about the datatypes in MATLAB (doesn't look like you are), you can pull the data in as a cell array without respect to format by specifying a third output argument to xlsread:
[~,~,rawData] = xlsread('my_file.xlsx',...)
After that, you just have to select the extent of the array you want to keep. If you don't want the first 5 rows by 14 columns of your excel data, set them to blank:
rawData(1:5,1:12) = {[]};
Finally, if you want to parse out the timestamps, use strsplit with the colon (:) as your delimiter.
for i = 1:size(rawData,1)
rawData{i,3} = strsplit(rawData{i,3},':')
end
Alternatively, if you just want to replace the colons with spaces, use regexprep:
for i = 1:size(rawData,1)
rawData{i,3} = regexprep(rawData{i,3},':',' ')
end
Once you've made all the changes you want, just write the data back to excel:
xlswrite('my_file.xlsx',rawData)
댓글 수: 5
Evan
2013년 7월 30일
The "too many inputs input arguments" error is occurring because you're leaving out the brackets [ ] around c:
c(:,3) = cellstr(datestr([c{:,3}],'HH MM SS'));
I'm not sure about your other error. What line of code causes it?
And if you want to split into three separate cells, you'll have to do another step after that in which you operate over each cell in the timestamps column and split it into three cells either with strsplit or regexp.
Image Analyst
2013년 7월 30일
Evan's answer says to read in the file, modify the data, and write it back out. This is the easiest way. If you want to do it "in place" and faster, then you can use ActiveX. While more complicated, it will be faster, especially if you need to do this in a loop where you need to do it many times, since it won't have to launch Excel twice and shutdown Excel twice for each and every file - you just open Excel once, process all the files, and shutdown Excel once. Opening Excel dozens of times can bring your program to its knees. If you want to do your processing in a loop over many files, then search this forum for ActiveX. I know I've given demos many times on it.
댓글 수: 0
Michal Kotze
2013년 7월 30일
Hi
Use Excel COM server
handel_Excel = actxserver('Excel.Application')
The help file on this can be found at the following link.
This will allow you to control Excel directly from Matlab.
Keep well and regards
댓글 수: 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!