Importing three dimensional text data.

조회 수: 1 (최근 30일)
Elliot
Elliot 2014년 4월 16일
댓글: dpb 2014년 4월 16일
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
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
dpb
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
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...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by