Info

此问题已关闭。 请重新打开它进行编辑或回答。

I have to compare data from matrix with different dimensions

1 次查看(过去 30 天)
Hi everyone,
I have to compare the data of two matrix with different dimensions but without 'intersect' because I need every data. I tried to do a for loop and if condition but I obtaine the error 'Matrix dimension must agree'. Is there someone that can help me? I'm attacching my code below. Thanks.
format long g
folderData = 'D:\Valerio\data\ACCESS1.0';
filePattern = fullfile(folderData, '*.xlsx');
xlsFiles = dir(filePattern);
nFiles = length(xlsFiles);
for ii = 1:nFiles
filename = fullfile(xlsFiles(ii).folder, xlsFiles(ii).name);
files{ii} = xlsread(filename);
end
IPCC = files(1);
ERA5 = files(2);
Data_IPCC = IPCC{:,1};
Data_ERA5 = ERA5{:,1};
Years_IPCC = Data_IPCC(:,1);
Years_ERA5 = Data_ERA5(:,1);
range_IPCC = length(Years_IPCC);
range_ERA5 = length(Years_ERA5);
index_year = []
for i = 1:range_IPCC
for j = 1:range_ERA5
if Years_IPCC == Years_ERA5
index_year(i,j) = j
end
end
end
  4 个评论
dpb
dpb 2020-3-12
Where's the second dataset and what is the wanted result from the two?
Look at ismember
Valerio Gianforte
Valerio Gianforte 2020-3-12
I want to obtain a match between all values. For now I have match til june 2004 and then the second dataset has a strange values. Basically I want to obtain two matrix where the data has match deleting rows where there is no match. In this way I should obtain two matrix with same domensions. I hope to has been clearer than before.
Below there is secondo dataset.
1985 1 1 0 0.883195698261261 4.25933790206909 284.282135009766
1985 1 1 60000 0.726142048835754 3.69971203804016 272.564300537109
1985 1 1 120000 0.715892493724823 3.59062361717224 271.423217773438
1985 1 1 180000 0.624481797218323 3.59896349906921 279.294616699219
1985 1 2 0 0.388713985681534 3.44896340370178 277.871398925781
1985 1 2 60000 0.268714010715485 3.04730319976807 274.012481689453
1985 1 2 120000 0.273071050643921 2.46767759323120 261.282165527344
1985 1 2 180000 0.297428041696548 2.61651635169983 250.423233032227
1985 1 3 0 0.307428032159805 2.68946266174316 246.141082763672
1985 1 3 60000 0.324606537818909 2.71074867248535 240.858932495117
1985 1 3 120000 0.496142029762268 2.90958738327026 237.717849731445
1985 1 3 180000 0.474606543779373 3.25087332725525 235.012451171875
1985 1 4 0 0.391660273075104 3.13908839225769 233.730331420898
1985 1 4 60000 0.371660262346268 2.96742796897888 236.871383666992
1985 1 4 120000 0.448963552713394 2.96780252456665 239.717834472656
1985 1 4 180000 0.506142020225525 3.30535507202148 234.858947753906
1985 1 5 0 0.473195791244507 3.36381936073303 231.294631958008
1985 1 5 60000 0.391660273075104 3.39921283721924 229.012466430664
1985 1 5 120000 0.280124783515930 3.49024939537048 222.448181152344
1985 1 5 180000 0.430249541997910 2.75166010856628 203.730331420898
1985 1 6 0 1.42240893840790 4.35830163955689 216.307098388672
1985 1 6 60000 2.14547991752625 5.41572904586792 254
1985 1 6 120000 2.11523056030273 5.60278320312500 277.987548828125
1985 1 6 180000 1.86805188655853 5.51278305053711 290.423217773438
1985 1 7 0 1.39498078823090 5.04830121994019 291
1985 1 7 60000 0.947677493095398 4.26394414901733 279.858917236328
1985 1 7 120000 1.04344534873962 4.06971216201782 264.141082763672
1985 1 7 180000 0.952034592628479 4.28253364562988 260.282165527344
1985 1 8 0 0.753445267677307 3.94253349304199 249.141082763672
1985 1 8 60000 0.912159383296967 3.91714000701904 233.294616699219
1985 1 8 120000 1.53689074516296 4.75444316864014 222.294616699219
1985 1 8 180000 1.70394432544708 5.38547992706299 225.012481689453
1985 1 9 0 1.66087341308594 5.13240861892700 253.012481689453

回答(1 个)

dpb
dpb 2020-3-12
Convert both to timetable or timeseries objects and use retime to synchronize the two.
  7 个评论
dpb
dpb 2020-3-13
编辑:dpb 2020-3-13
And the code you tried that didn't work (and what went wrong with it) as well...
Guillaume
Guillaume 2020-3-13
I'm a bit unclear as to what the desired output is.
There are 64 dates of the ERA files not found in the ACCESS file, and 67 dates of the ACCESS file not found in the ERA files. How should identical be merge? What should be done about the dates not present in one file and not the other?

此问题已关闭。

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by