I have to compare data from matrix with different dimensions

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 Comments

Can you give an example with sample matrices A and B, and also explain your required output? Which line is giving the error? Attaching a sample dataset will also help.
I'm attacching below dataset:
1985 1 1 0 1.37400000000000 11.0830000000000 55.0240000000000
1985 1 1 6 1.87800000000000 9.66900000000000 57.3230000000000
1985 1 1 12 1.44800000000000 9.29700000000000 57.8670000000000
1985 1 1 18 1.01100000000000 9.04300000000000 59.2970000000000
1985 1 2 0 0.801000000000000 8.58700000000000 29.5170000000000
1985 1 2 6 0.787000000000000 3.72800000000000 257.510000000000
1985 1 2 12 0.762000000000000 4.06700000000000 259.778000000000
1985 1 2 18 0.514000000000000 9.66500000000000 21.6490000000000
1985 1 3 0 0.504000000000000 7.15900000000000 29.9860000000000
1985 1 3 6 0.528000000000000 7.00900000000000 16.4780000000000
1985 1 3 12 0.498000000000000 7.03400000000000 31.6410000000000
1985 1 3 18 0.621000000000000 6.92300000000000 74.2660000000000
1985 1 4 0 0.610000000000000 3.55700000000000 82.2030000000000
1985 1 4 6 0.560000000000000 10.1440000000000 67.8760000000000
1985 1 4 12 0.526000000000000 9.99100000000000 55.5480000000000
1985 1 4 18 0.500000000000000 6.67200000000000 58.3460000000000
1985 1 5 0 0.403000000000000 6.36300000000000 56.4550000000000
1985 1 5 6 0.340000000000000 6.14100000000000 57.9960000000000
1985 1 5 12 0.298000000000000 5.34300000000000 57.1270000000000
1985 1 5 18 0.783000000000000 5.86500000000000 54.0100000000000
1985 1 6 0 1.82600000000000 6.86800000000000 54.3830000000000
1985 1 6 6 2.94400000000000 7.88000000000000 56.0240000000000
1985 1 6 12 2.66800000000000 9.21200000000000 61.7850000000000
1985 1 6 18 2.17100000000000 9.66300000000000 60.4400000000000
1985 1 7 0 1.63400000000000 9.53700000000000 59.3800000000000
1985 1 7 6 1.25600000000000 9.43500000000000 56.1940000000000
Both of matrix have the same structure but different dimension. Furthermore the error is at the end of for loop. Thanks.
Where's the second dataset and what is the wanted result from the two?
Look at ismember
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

Answers (1)

Convert both to timetable or timeseries objects and use retime to synchronize the two.

7 Comments

... or synchronize even!
Aren't timeseries being deprecated. I would strongly recommend timetable. Even just a table would be better than using matrices.
"Aren't timeseries being deprecated"
Nothing in R2019b doc about. It's a hard one to know whether to use imo. It doesn't seem to really have much that I've found really totally not easy to have done without.
the 'synchronize' command doesn't work and 'timetable' too. I converted the Years (first column) with timeseries and then I tried to use "synchronize" and "retime" but nothing to do.
synchronize, timetable, etc. all work, you'd think by now somebody would have noticed if they didn't. Now, the way you tried to use them may not have worked but it's hard to tell what you did wrong if you don't tell us what you did.
Also, attach demo files rather than copy/pasting content. It's much easier for us to help you if we don't have to recreate your files just to figure out what to do.
Ok, I'm attacching compressed folder that contains the two xlsx files.
And the code you tried that didn't work (and what went wrong with it) as well...
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?

This question is closed.

Products

Release

R2018b

Asked:

on 12 Mar 2020

Closed:

dpb
on 14 Mar 2020

Community Treasure Hunt

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

Start Hunting!