이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Importing .mat files with text also
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I'm trying to import large tables saved as a .mat file, but MATLAB won't load the file. The table is set up as a column matrix with ['str',#,#,#,#,#,#]. The str is a date file which could be converted to date, but takes a long time to do. (3.5million rows). I'm looking for a way to get this to import into matlab, but load won't work, and textscan doesn't either. Load is trying to pick it up as a ASCII file (due to the string) and textscan won't pick it up because it isn't a text file. Any suggestions?
Edit: Doing more research, could this also be related to my version of everything being 32bit rather than 64? The .mat file is only 36MB, so it didn't occur to me until I kept crashing the program doing some sidework.
댓글 수: 11
José-Luis
2014년 7월 14일
load will read binary .mat files, unless you pass it the -ascii flag, in which case it will read text. What does your command look like?
Have you read the documentation:
doc load
Mike Beacham
2014년 7월 14일
편집: Mike Beacham
2014년 7월 14일
Hey Jose,
Short version - If I'm understanding correctly, for load to work, it has to be an entirely binary file, and for ASCII to work, it needs to be a text file?
Longer Version - I have tried load, load( ,-mat) and load( ,-ascii). They all keep giving errors. Just load gives error "Can't read file filename.mat." If I try adding -mat tag, I get the same thing, which makes sense. If I try as an -ascii, "Unknown text on line number 1 of ASCII file filename.mat "MATLAB"." And I've read through the documentation a few times, but it wasn't helping me too much. I was just getting on here to mention I might be overloading the 32 version I'm running, but it's nowhere near the 4G limit on file size. If I use some other data of about 10% the size, MATLAB crashed halfway through my script.
Star Strider
2014년 7월 14일
Please post relevant parts of your code. Without it we can only guess.
Also, what version of MATLAB was the .mat file saved with? Do you have access to the script that saved it?
Mike Beacham
2014년 7월 14일
The files were saved by converting a CSV to .mat file through MATLAB on R2014a 64bit, then they were given to me. I'm running R2014a 32bit.
I don't even have the load portion written into the script. I'm currently just trying to get the thing to load. I'm trying to load various files, and then the script picks columns out and does calculations.
>> load('filename.mat','-ascii');
Error using load
Unknown text on line number 1 of ASCII file filename.mat
"MATLAB".
>> load('filename.mat')
Error using load
Can't read file filename.mat.
>> load('filename.mat','-mat')
Error using load
Can't read file filename.mat.
>>
José-Luis
2014년 7월 14일
.mat can also be a "Microsoft Access Table". Are you sure you have the right files? Further sanity check: Are the files located in your current directory, or a directory that's in the path?
Mike Beacham
2014년 7월 14일
good checks, They are MATLAB files, so not Access Tables, and I checked my paths, the folder was a few down the list, but when I moved it to the top, same problems.
dpb
2014년 7월 14일
편집: dpb
2014년 7월 14일
...The files were saved by converting a CSV to .mat file through MATLAB on R2014a 64bit, then they were given to me. I'm running R2014a 32bit....
I don't have a 64-bit system to check on so can't answer whether there's a compatibility issue there or not. Official TMW support should be able to tell or the supplier of the files to check the doc for the 64-bit version for any caveats listed there or for any switches can use if known need them to be 32-bit compatible.
ADDENDUM
Are MAT-files compatible between the 32-bit and 64-bit versions of MATLAB?
MAT-files created with 32-bit versions and 64-bit versions of MATLAB are compatible with each other.
Note: With large data sets that use the -7.3 MAT-file format, it is possible for the 64-bit version of MATLAB to produce a MAT-file that is too large for the 32-bit version of MATLAB.
That implies other than the overall file size should be compatible if save was how files were actually created.
END ADDENDUM
Other than that, we're still guessing -- if can post the segment of code that did the save to create the files and the relevant information for the variables within, then could have something to go on to know what the files really are.
It would be of interest to see what
whos -file 'filename.mat'
returns and if could get it from both machines that would be even better.
Mike Beacham
2014년 7월 14일
편집: Mike Beacham
2014년 7월 14일
The file was saved using te import data function on the command window, not actually writen code. It started as a CSV file. I wanted it to export as a table, so I chose that option, labeled the headings, and then saved as a .mat file. It opens just fine on the 64 bit machine. If I enter in whos there I get
>> whos('-file','siws01.mat')
Name Size Bytes Class Attributes
siws01 - 562714480 table
Running on my 32 bit system, I get a warning that says unknown MAT-file error.
>> whos('-file','siws01.mat')
Warning: Unable to read some of the variables due to unknown MAT-file error.
Hmmm. I think that means my problem is more related to file type as opposed to text vs binary inputs. Thanks everyone. I'll figure this out and then see if I still have the importing problem.
dpb
2014년 7월 14일
Indeed your surmise is correct. I don't have a version with the table type so can't test. I'd suggest after you read the data in if the point is to transport the data to the other machine, use
save filename txtvar numericvars
will be more compact and you can then just load the variables and create the table on the target machine.
Mike Beacham
2014년 7월 15일
It turns out my whole MATLAB install was corrupt, I re-installed and it started loading them. Thanks for all the help guys!
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)