这是一段代码,可帮助您在包含每个曲目信息的结构中获取所需的数据。
在我的示例代码中,我生成时间,X和Y坐标的虚拟值,然后将它们放入单元格数组中,该单元格数组最终包含您为每个时间点指定格式的数据。
我假设有关轨道的信息存储在名为DataStruct的结构中,其中名为X_Coord和Y_Coord。在你的情况下,这个信息是在一个矩阵中,因此在结构中执行索引的方式将是不同的。正如你在评论中所说的那样,矩阵的大小是1x8(TimePoints),所以你将不得不重新整形以便更容易地访问其中的元素。
clc;
clear all;
% Generate dummy values
for 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 and put into cell array, along with the
% time.
for k = 1:length(DataStruct)
Data_Cell(k,:) = {(k) (DataStruct(k).X_Coord) (DataStruct(k).Y_Coord)};
end
Data_Cell
这导致下面的单元阵列中:
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]
然后可以转换为使用cell2mat
双打的阵列; 希望能帮助你开始!
编辑: 下面按照你的评论,这里是你可以做什么,以确定都是NaN的广告的X和Y坐标,将它们存储在一个新的矩阵及其相应的时间沿着:
DummyArray = zeros(10,3);
% Generate dummy array with numbers and 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];
其中给出此虚设矩阵:
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 which both x and y coordinates are actual numbers
NotNaN = DummyArray(~isnan(DummyArray(:,2)) & ~isnan(DummyArray(:,3)));
%Use logical indexing to retrieve the corresponding time, x- and y
%coordinates all in the same matrix.
FinalMatrix = [DummyArray(NotNaN,1) DummyArray(NotNaN,2) DummyArray(NotNaN,3)]
的输出是下面的:
FinalMatrix =
2 2 21
5 5 51
7 7 71
8 8 81
然后你去!
对于含有x坐标,y坐标等的矩阵,你能更具体一些吗?例如它的大小是多少? – 2014-09-10 17:12:28
它是1x(8t)double,其中t是轨道的lentgh - 例如,具有20个时间点的轨道导致1x160双倍。 – mtmtmt 2014-09-10 17:21:37
你的例子不是一个单元格数组,你是否需要它是一个单元格数组,或者你对一个双精度数组满意吗? – 2014-09-10 17:43:13