Question

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.

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.

Sample of a few cells

Data Size 1x1210

Data{366}(1:14) Size 366x1

Small sample:

    '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) Same size as 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'

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.

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)

Was it helpful?

Solution

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{:});

Then

idx = strcmp(uID2,'06-019-5001') & strcmp(Date2,'01-Jan-2011');
out = Data2(idx);

You can also create a table (in the late MATLAB versions) for much easier queries.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top