Problems with importing Excel csv format
조회 수: 12 (최근 30일)
이전 댓글 표시
Hi. I have a lot of excel files with extension .csv that I would like to import to matlab. I think the problem is not really matlab oriented, maybe more excel. When I import the file emediately, I get the message "No data is available for review" or something like that. But if I just press the save button in my excel spread file and then click "yes" to some " format is not compatible with csv.." question, then it works again.
This clicking is very time consuming because of the many files. Have someone had related problems and solved it or any solutions to my bad explanation? Thanks on forehand! Fredrik
댓글 수: 1
Kevin
2011년 10월 19일
Email me a small sample of your .csv file and I can try to help you import it into matlab.
답변 (9개)
Fangjun Jiang
2011년 10월 19일
The message "some format is not compatible with csv.." indicates that the file contains some formatting that is not supported by .csv file.
Where does the .csv file come from? Can you use csvread() or xlsread() directly without opening the file in Excel? What if you open the .csv file with an text editor like M-editor. Do you see anything abnormal?
I suspect your .csv file has some problems. Use a text editor such as Notepad, Wordpad etc. to open it and visually inspect it to see if anything out of ordinary.
In MATLAB, you can use Excel COM server, go through a loop, open each .csv file and save it again. This is to utilize Excel to fix the problem. You probably can do that in Excel alone using Macros.
If you are using the Excel COM server, the following snip of code can be used.
xlCSV=6; %this constant is defined by MS Excel
ExcelApp.DisplayAlerts=false;
WorkBook.SaveAs(CSV_File,xlCSV);
댓글 수: 0
Kevin
2011년 10월 22일
Why are you opposed to using xlsread?
xlsread reads your file in perfectly from what I can see...
Try:
[Data Text] = xlsread('000169_2011-08-18_stat.csv');
댓글 수: 0
Walter Roberson
2011년 10월 22일
csvread() and dlmread() is documented as only reading data that has no text in it at all.
You can get around that restriction if you specify cell ranges, starting with a cell "below" any text lines and to the right of any text. The lines at the top that you skip can contain anything, but any cells to the left that you skip must not have any whitespace and must not have an embedded commas.
댓글 수: 0
Fredrik
2011년 10월 24일
댓글 수: 1
Fangjun Jiang
2011년 10월 24일
I saw you had your code as "exlFile = exlWkbk.Open([docroot '/techdoc/matlab_external/examples/000169_2011-08-18_stat.csv'])" so I though you've gone through the Excel COM server code stuff. To apply the technique to your code, you'll replace 'WorkBook' with 'exlWkbk', replace 'CSV_File' with whatever the variable for your new .csv file name.
Fredrik
2011년 10월 24일
댓글 수: 1
Fangjun Jiang
2011년 10월 24일
Darn, forgot the [Num, Txt, Raw]=xlsread() completely! Stuck with the impression that your .csv file has some problems! One reminder, str2double() works on cell array so you don't need to go through a for-loop. try str2double({'1','2'})
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!