Reading a 3 dimensional array into MATLAB from a text file
이전 댓글 표시
I have an external program that generates text output files with arrays formatted in a "C/C++ ish" syntax. I am trying to read 3 dimensional array data into Matlab, but haven't found a way to do this.
This is the format as it appears in the text file (shown here for an example 2x3x4 array): threeDims = { { { 111, 112, 113, 114 }, { 121, 122, 123, 124 }, { 131, 132, 133, 134 } }, { { 211, 212, 213, 214 }, { 221, 222, 223, 224 }, { 231, 232, 233, 234 } } }
For one or two dimensional arrays I can write a script that plays some find and replace games to replace curly braces with square braces, fix commas and semicolons, etc. and end up with a readable MATLAB variable declaration.
However, for a 3-D array, I can't figure it out. From the MATLAB help documentation I've seen, it looks like MATLAB wants you to explicitly index through the third dimension, assigning 2D arrays for each.
Is there an easier way? It just seems that since I have such a nice looking (and easy to generate) output from my other program, I should be able to import it into MATLAB for processing without a huge headache.
Thanks for any help you can provide, Mike
답변 (1개)
Walter Roberson
2011년 3월 4일
Sorry, Matlab does not provide any convenient syntax for entering multidimensional arrays.
In the meanwhile, you can use
cat(3, [111, 112, 113, 114;
121, 122, 123, 124;
131, 132, 133, 134], ...
[211, 212, 213, 214;
221, 222, 223, 224;
231, 232, 233, 234] )
카테고리
도움말 센터 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!