Importing three dimensional text data.
古いコメントを表示
I apologize if this answer is trivial, but after searching the web, and the MATLAB documentation, I have yet to find a clear answer.
I have three dimensional data describing the growth of 30 girls aging from 4-15. Full documentation (& corresponding data) here: http://three-mode.leidenuniv.nl/data/girlsgrowthcurvesinfo.htm
The data is given in the following format:
j=1,.,J=8
|-----|i=1
| |i=2
| |.. k= 1
| |..
|_____|i=I=30
|-----|i=1
| |i=2
| |.. k= 2
| |..
|_____|i=I=30
|-----|i=1
| |i=2
| |.. k=12
| |..
|_____|i=I=30
With 'i' representing the girl, 'j' representing the body part being measured, and 'k' representing the ages at which everything is measured.
Using the NWAY toolbox, I can model the data so to answer 3-way questions.
MY QUESTION: How do I import this data into MATLAB? (i.e. a 30x8x12 Matrix)
Thanks
回答 (1 件)
dpb
2014 年 4 月 16 日
x=textread('datafile.dat'); % read the data (2D) into an array -- *textread* will do nicely
x=reshape(x.',30,8,[]); % reshape to 3D by row,column,plane
4 件のコメント
Elliot
2014 年 4 月 16 日
Elliot
2014 年 4 月 16 日
dpb
2014 年 4 月 16 日
It's the transpose operator -- ML is column-major storage so that orders the 2D array by row instead of column that would be by default.
The latter is a problem -- means the data aren't all there in your file or somesuch. It's mandatory that if have full dataset as described of 8x30 per plane the total number must be divisible by 240.
What is
numel(x)
after the textread and does it appear you actually have the correct data file to start with (by looking at a few values)?
dpb
2014 年 4 月 16 日
OK, my thinker isn't thinkering very good at the moment...the following works altho should be able to get there w/o the loop--
x=textread(...
tmp=reshape(x.',8,30,[]);
x=zeros(30,8,12);
for i=1:size(tmp,3)
x(:,:,i)=tmp(:,:,i).';
end
I'm not getting why I can't get the right order permutation here now...
カテゴリ
ヘルプ センター および File Exchange で Data Import and Export についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!