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
Walter Roberson 2011 年 3 月 4 日

0 投票

Sorry, Matlab does not provide any convenient syntax for entering multidimensional arrays.
You may wish to add your input and vote to this previous enhancement request
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 ExchangeCell Arrays についてさらに検索

製品

質問済み:

2011 年 3 月 4 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by