I have to compare data from matrix with different dimensions
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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
Ameer Hamza
on 12 Mar 2020
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.
Valerio Gianforte
on 12 Mar 2020
dpb
on 12 Mar 2020
Where's the second dataset and what is the wanted result from the two?
Look at ismember
Valerio Gianforte
on 12 Mar 2020
Answers (1)
dpb
on 12 Mar 2020
0 votes
Convert both to timetable or timeseries objects and use retime to synchronize the two.
7 Comments
dpb
on 12 Mar 2020
"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.
Valerio Gianforte
on 13 Mar 2020
Guillaume
on 13 Mar 2020
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.
Valerio Gianforte
on 13 Mar 2020
Guillaume
on 13 Mar 2020
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.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!