Extract Data from Structure and Transfer it into Cell Array

6 次查看(过去 30 天)
Hello everybody,
I am quite new to Matlab and can't come up with a solution to the following problem:
From a single particle tracking program that uses Matlab (uTrack, to be precise) I get the tracking results as a structure. Inside this strucutre, the tracks of every particle is stored within a cell array. In this cell array, the tracks can then be found as a matrix (two other matrices are also there with other information) in the following way:
x coord / y coord / z coord / Amplitude / dx / dy / dz / dA ...
This would be the first time point. Then it starts again with x coord, y coord, and so on for the second time point until the end.
For further evaluation, I only need the x and the y coordinates in a cell array in the following form
[t1 x1 y1;
t2 x2 y2;
t3 x3 y3;
...]
with on element in the cell array for each particle.
Therefore, I need to somehow extract the x and y coordinates, transfer them and add the time information in the first column with the correct lenght.
I have already tried to convert the data to a matrix, but the problem here is that the tracks have of course not all the same lengths. I get then a lot of NaN which cause problems in the following steps...
Any help would be very much appreciated!
  2 个评论
Guillaume
Guillaume 2014-9-11
I don't really understand the whole details of your structure, could you show an example?
Similarly it's not very clear what you want out of it? A cell array of matrices (one per particle)? Again an example would help.
LM
LM 2014-9-12
Thank you for your answer! I have attached the output-file (outputstruct.mat) of the tracking program. The data I need is inside the structure "tracksFinal". If you open it, you will find inside a Nx1 structure, N standing for the number of tracks - in this example 855. Inside each of these structures are three doubles. The double "tracksCoordAmpCG" contains the relevant information in the form I worte above:
x coord / y coord / z coord / Amplitude / dx / dy / dz / dA ...
Therefore, it is just one row with 8 elements per time point. Relevant are only the x and y coords.
I have also attached another type of output - it is the same data, but in a matrix style (outputmatrix.mat). I don't know what is easier to deal with. In the matrix there are a lot of NaNs which may cause problems...
The infromation about the time is not written the output, this would be 0.05 s/frame - so 0/0.05/0.1/0.15 etc. This would be added seperately.
In the end, I need the following: A cell array with one element for each track like this:
<TL1x3 double>
<TL2x3 double>
<TL3x3 double> and so on
TL stands for the track length and the 3 originiates from the three columns of each track: One for the time, one for the x and one for the y coord, so every element looks like this:
t1 x1 y1
t2 x2 y2
t3 x3 y3 and so on
As I mentioned, no NaNs may appear in the coords. +
Again, thank your very much for your help!

请先登录,再进行评论。

回答(1 个)

Guillaume
Guillaume 2014-9-12
First, a point of terminology:
tracksFinal is the Nx1 structure, there is no structure inside. It consists of three fields (not doubles), tracksCoordAmpCG is one of the field and it contains a row vector consisting of repeats of sequence of 8 elements where each element is as you've described.
I'm still not entirely clear on what exactly you want the output to look like, so first, I'll show you a few things:
To convert the values of one field of a structure array into a cell array of those value:
tcampCG = {tracksFinal(:).tracksCoordAmpCG}
To convert a row vector of 8 repeating elements into an Mx8 matrix, use reshape:
tcampCG1 = reshape(tracksFinal(1).tracksCoordAmpCG, 8, [])'
In the end, I think the following may be what you want:
tcampCG = {tracksFinal(:).tracksCoordAmpCG}; %transform field into cell array
for trackindex = 1:numel(tcampCG) %iterates over the elements of the cell array
tcampCGi = reshape(tcampCG{trackindex}, 8, [])'; %reshape element to 8 columns
tracktimes = (0:size(tcampCGi, 1)-1) * 0.05; %calculate time
tcampCG{trackindex} = [ tracktimes', tcampCGi(:, [1 2])]; %concatenate time with column 1 and 2 and put back into cell array
end

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by