Matlab: Extract Data from Structure and Transfer it into Cell Array -


i quite new matlab , can't come solution following problem:

from single particle tracking program uses matlab (utrack, precise) tracking results structure. inside strucutre, tracks of every particle stored within structure. in structure, tracks can found matrix (two other matrices there other information) in following way:

x coord / y coord / z coord / amplitude / dx / dy / dz / da ... 

this first time point. starts again x coord, y coord, , on second time point until end.

for further evaluation, need x , y coordinates in cell array in following form

[t1 x1 y1;  t2 x2 y2;  t3 x3 y3;  ...] 

with 1 element in cell array each particle.

therefore, need somehow extract x , y coordinates, transfer them , add time information in first column correct lenght.

i have tried convert data matrix, problem here tracks have of course not same lengths. lot of nan cause problems in following steps...

any appreciated!

here bit of code fetch data want in structure containing informations each of tracks.

in sample code, generate dummy values time, x- , y coordinates , put them in cell array, contains data in format specified, each time point.

i'm assuming information track stored in structure called datastruct, fields named x_coord , y_coord. in case, information in matrix , way in indexing performed in structure different. said in comments, size of matrix 1x8(timepoints), have play around reshape example make easier access elements in it.

clc; clear all;  % generate dummy values t = 1:10 datastruct(t).x_coord = t; datastruct(t).y_coord = 10*t+1; end  data_cell = cell(length(datastruct),3); % pre-allocation  % fetch each field of interest , put cell array, along % time. k = 1:length(datastruct)      data_cell(k,:) = {(k) (datastruct(k).x_coord) (datastruct(k).y_coord)};  end  data_cell 

this results in following cell array:

data_cell =       [ 1]    [ 1]    [ 11]     [ 2]    [ 2]    [ 21]     [ 3]    [ 3]    [ 31]     [ 4]    [ 4]    [ 41]     [ 5]    [ 5]    [ 51]     [ 6]    [ 6]    [ 61]     [ 7]    [ 7]    [ 71]     [ 8]    [ 8]    [ 81]     [ 9]    [ 9]    [ 91]     [10]    [10]    [101] 

you can convert array of doubles using cell2mat; hope helps started!

edit: following comment below, here can identify x , y coordinates both nan ad store them in new matrix along corresponding times:

dummyarray = zeros(10,3);  % generate dummy array numbers , nans. dummyarray(:,1) = 1:10; dummyarray(:,2) = [1 2 nan nan 5 6 7 8 nan nan]; dummyarray(:,3) = [nan 21 nan 41 51 nan 71 81 91 nan]; 

which gives dummy matrix:

dummyarray =           1     1   nan          2     2    21          3   nan   nan          4   nan    41          5     5    51          6     6   nan          7     7    71          8     8    81          9   nan    91         10   nan   nan  %find row indices in both x , y coordinates actual numbers notnan = dummyarray(~isnan(dummyarray(:,2)) & ~isnan(dummyarray(:,3)));  %use logical indexing retrieve corresponding time, x- , y %coordinates in same matrix. finalmatrix = [dummyarray(notnan,1) dummyarray(notnan,2) dummyarray(notnan,3)] 

the output following:

finalmatrix =       2     2    21      5     5    51      7     7    71      8     8    81 

and there go!


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -