Textscan with many requirements
조회 수: 5 (최근 30일)
이전 댓글 표시
I’ve tried all sorts of methods, from textscan to textread but I am struggling to read the excel file. Only allowed to use textscan/textread, not xlsread. I've utilized whatever forum question I came across, but all did not help me much.
Right now, I am getting "Too many output arguments." Even after I limit to [Ar] = textscan(filepath,...etcetc); , what I get is not all the data I want. I would like to read every data available.
filepath = 'file.xls';
[Ar,B,C,D,E,F,G,H,I,J,K,L,M] = textscan(filepath,'%f %c %c %c %c %{yyyy}D %c %c %f %f %f %c %c','headerlines',2,'delimiter',',','emptyvalue',NaN);
댓글 수: 0
답변 (2개)
Walter Roberson
2018년 9월 24일
편집: Walter Roberson
2018년 9월 24일
You have attached a file with an xls file extension. Xls files are always binary files that would be rather difficult to process with textscan as that routine deals with text files.
The content of the file you attached is not either an xls file nor an xlsx file. It is an XML file created by Microsoft Word. It might even be the key XML file that would be present inside an xlsx file (xlsx are zipped files of directories of XML documents).
It is not especially easy to use textscan to parse an XML document, but you could probably extract key information from it if you were persistent enough.
If you have an imposed requirement to use textscan to read the contents then you could use a %s format with whitespace and delimiter set empty to just read everything as one string. Then pass the string to an XML parser, or use regexp to parse it. This would stay within the letter of the requirement while completely violating the spirit of the requirement, perhaps, but trying to use textscan to parse an XML file is not worth the effort unless the point of the exercise is to become a textscan expert past all reasonable textscan use.
댓글 수: 6
Walter Roberson
2018년 9월 24일
Missing rows at the end usually mean that the file format does not match the format you are scanning with.
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!