How to intersect until thirteen Matrices if it were present two conditionals?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello guys.
I have thirteen matrices with two columns by ten thousands rows by each one; the first column corresponds to the vector time and the second column to a value (air temperature).
The instrument used to record the air temperature in thirteen cities, has (1) some missing records in time or (2) NaN values. For comparative porpuses I need to consider only the records of temperature which coincide in time in all the cities, discarding if NaN values were recorded.
For this reason, I need to apply the command "intersect" to all Matrices (or other related command), to generate another Matrix which preserves the values of temperature from all sites, if the next conditionals are present (in this order):
1) Intersect only the rows which contains the common value at the first column in all thirteen Matrices (time vector), and after that concatenate all the temperature values from all Matrices; with this will be generated a Matrix of fourteen columns (time vector and the values of temperature from therteen cities).
2) After that, if it were present a NaN value in some column (or more), eliminate by complete the whole row.
Thanks in advance.
Miguel.
0 件のコメント
採用された回答
Walter Roberson
2016 年 3 月 8 日
Toss all of the first row into a continuous vector by concatenating. histc() or histedges() the vector against unique() of that vector. The bins that have a count of 13 are present in all of the matrices, so extract that subset of the unique values.
Now for each matrix, you can extract the rows where the first column ismember() the common points.
3 件のコメント
Walter Roberson
2016 年 3 月 8 日
Ms = {Matrix1, Matrix2, Matrix3, ... Matrix13};
num_M = length(Ms);
allM = vertcat(Ms{:});
allM( any(isnan(allM),2), :) = [];
allTime = allM(:,1);
[uniqueTimes, ~, timeGroups] = unique(allTime);
TimeCounts = histc(timeGroups, 1:length(uniqueTimes));
consistent_times = uniqueTimes(timeCounts == num_M);
selected_rows = cell{1, num_M};
for Midx = 1 : num_M
this_M = Ms{Midx};
[~, row_idx] = ismember(consistent_times, this_M(:,1));
selected_rows{Midx} = this_M(row_idx,2);
end
extracted_M = horzcat(consistent_times, selected_rows{:});
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!