How to convert data file from grid-format into a table
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi everyone! I am a fairly newbie in MATLAB and I am having a pretty bad issue converting a data file from a certain format into a simple table. The situation is briefly explained as follow: Datas are initially organized like this in the form of grid:
NaN 1 2 3 4 5
1
2 values
3
4
5
repeated 5 times. The first row for each matrix is the Y coordinate, and the first column is the X coordinate, the values are intensities values. The repetition is for each z slide, in this example 5 slides. Now, the final format that I need is a table, in the following format:
x y z values
1 1 1 xx
2 1 1 xx
3 1 1 xx
4 1 1 xx
5 1 1 xx
1 2 1 xx
2 2 1 xx
3 2 1 xx
4 2 1 xx
5 2 1 xx
1 3 1 xx
2 3 1 xx
3 3 1 xx
4 3 1 xx
5 3 1 xx
1 4 1 xx
2 4 1 xx
3 4 1 xx
4 4 1 xx
5 4 1 xx
1 5 1 xx
2 5 1 xx
3 5 1 xx
4 5 1 xx
5 5 1 xx
1 1 2 xx
2 1 2 xx
3 1 2 xx
4 1 2 xx
5 1 2 xx
etc......
In the example here I wrote 5x5x5 blocks, but in my concrete case is 200x200x50. Here is what I was able to do:
A=X;
A(:,1)=[];
i=0
for u=1:200+1:(length(A));
A(u-i,:)=[];
i=i+1;
end;
%I delete all rows without values but with the x coordinates
j=1;
B=ones(2E6,4);
y=([1:1:200])';
o=(ones(200))';
for i1=1:200:(length(A)-200);
x=1;
for i2=i1:1:(i1+199);
x=x+1
V=A(i2,:);
% A(i2,:)=B(j:j+199,1)';
putBinA(B,V,j,4);
putBinA(B,y,j,1);
putBinA(B,o,j,2);
% B(j:j+199,1)=y;
% B(j:j+199,2)=o;
j=+200;
end
end;
where I am using putBinA function from http://www.mathworks.com/matlabcentral/fileexchange/19989 in order to insert the 200-long portion of the original Matrix A into the right position of B at the 4th column, indexed by j. The problem is that the function putBinA gives me back error saying that the Matrix to be inserted must be smaller, as it is. I can't move forward but I am sure some cool guy here can give me some clues :D ...
Thanks a lot,
Mitch
0 Kommentare
Antworten (1)
bym
am 7 Mai 2012
a = rand(4,4,2); % make up some data
b = a(:);
[r,c,p]=ind2sub([4 4 2],1:32);
[r',c',p',b]
1 Kommentar
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!