问题描述
我将单元格另存为Data
,Date
,Lat
,Lon
和uID
.有1210个单元,每个单元有365天或366天. 1210个单元是2008-2014年的网站总数(因此有很多重复-对于具有2008-2014年数据的网站,它会显示7次).这些单元格中每行的365或366行是该位置多年来的一年数据.
I have cells saved as Data
, Date
, Lat
, Lon
, and uID
. There are 1210 cells and each cell has either 365 or 366 days. The 1210 cells are the total number of sites for 2008-2014 (so there are a lot of repeats - for a site that has data from 2008-2014, it would show up 7 times). The 365 or 366 rows in each of these cells are the data for one year for that location for the years.
如何找到日期匹配的索引并将所有Data
,uID
,Lat
和Lon
串联到列上?现在,Data {i}会拥有一个站点一年的数据,但是我想将一天的数据,纬度和经度信息合并到单独的Data
,Lat
和Lon
列中,然后转到下一个单元格,该单元格将在第二天提供该信息.这样,我最终可以只通过遍历各列就可以在一天内绘制数据.
How can I find the indexes where the the Date matches and concatenate all the Data
, uID
, Lat
, and Lon
into on column? Right now, Data{i} would have the data for one site for one year, but I want to combine the data, lat, and lon information for one day into separate Data
, Lat
, and Lon
columns, then move on to the next cell, which would have that information for the next day. That way, I can eventually plot the data in one day by just running through the columns.
一些细胞的样本
Data
大小1x1210
Data{366}(1:14)
尺寸366x1
小样本:
'8'
'10.9'
'9.7'
'8.9'
'10.2'
'8.8'
'13.5'
'6.7'
'10'
'15.8'
'11.6'
'12.9'
'11.8'
'10.2'
Date{366}(1:14)
与Data
'01-Jan-2011'
'02-Jan-2011'
'03-Jan-2011'
'04-Jan-2011'
'05-Jan-2011'
'06-Jan-2011'
'07-Jan-2011'
'08-Jan-2011'
'09-Jan-2011'
'10-Jan-2011'
'11-Jan-2011'
'12-Jan-2011'
'13-Jan-2011'
'14-Jan-2011'
这将用于一个uID
.因此uID{366}
为'06 -019-5001'.对于uID{367}
,日期将相同,但是Data{367}
值将不同.
This would be for one uID
. So the uID{366}
would be '06-019-5001'. For uID{367}
, the dates would be the same, but the Data{367}
values would be different.
我想查找所有Date
= '01 -Jan-2011'的情况,因为对于每个uID
,都会有Date
= '01 -Jan-2011'和不同的Data
,Lat
和Lon
.然后,当天将所有这些都连接到带有Data
的列中(与Lat和Lon相同,但是由于它们的大小相同,因此处理过程也相同)
I would want to find all of the cases where Date
= '01-Jan-2011' since for each uID
, there would be a Date
= '01-Jan-2011' and a different Data
, Lat
, and Lon
. Then, I would concatenate all of them into a column with the Data
on that day (Same for Lat and Lon, but since they are the same size, it would be the same process)
推荐答案
如果您所有由字符串组成的单元格数组的单元格大小均相同(包括uID),则我会将所有内部单元格连接为字符串:
If all of your cell arrays of cell arrays of strings are of the same size (including uID), I would concatenate all the internal cells into a cell array of strings:
Data2 = cat(1,Data{:});
Date2 = cat(1,Date{:});
...
uID2 = cat(1,uID{:});
然后
idx = strcmp(uID2,'06-019-5001') & strcmp(Date2,'01-Jan-2011');
out = Data2(idx);
您还可以创建一个表(在最新的MATLAB版本中)以简化查询.
You can also create a table (in the late MATLAB versions) for much easier queries.
这篇关于查找值匹配的地方并与列向量MATLAB合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!