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
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.
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!