查找值匹配的地方并与列向量MATLAB合并

编程入门 行业动态 更新时间:2024-10-27 02:27:31
本文介绍了查找值匹配的地方并与列向量MATLAB合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将单元格另存为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合并

本文发布于:2023-11-22 20:18:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1618867.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:向量   并与   地方   MATLAB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!