Comparing different size of Matrix Problem
6 次查看(过去 30 天)
显示 更早的评论
Hi all! I am trying to compare different sizes of matrix. One matrix is in 47*1 and the other one is in 57*1 size. However, they are both showing the same information (starting from 0.02 to 0.95). Can I know if there is a way to process the second matrix so I can use the first matrix to compare with it? (eg. Subtraction- differences)
0 个评论
回答(2 个)
Pulkit Goel
2020-7-8
To compare element wise, you need both matrix to be of equal size. In case you don't want that, you have to limit yourself to size of smaller matrix.
Here, you can make matrix 'a' of size 47*1 to size of 57*1 by appending zeros wherever you want, maybe at end
a=[a, zeros(10,1)]
Or you may truncate 2nd matrix to size of 1st one
a=a(1:47)
0 个评论
Walter Roberson
2020-7-8
In some cases it might make sense to use Dynamic Time Warping to compare the vectors; see https://www.mathworks.com/help/signal/ref/dtw.html
If what you had was two vectors of different time bases, and associated values for each, like t1, y1 and t2, y2, and length(t1) ~= length(t2) but they cover roughly the same time span, then there are some different ways to compare:
m1 = t1 >= min(t2) & t1 <= max(t2);
m2 = t2 >= min(t1) & t2 <= max(t1);
both_t = union(t1(m1), t2(m2));
y1interp = interp1(t1(m1), y1(m1), both_t);
y2interp = interp1(t2(m2), y2(m2), both_t);
y1my2 = y1interp - y2interp;
plot(both_t, y1my2)
This code specifically takes into account that the timespans covered might not be exactly the same, and trims the data down to the overlap. Then it take all of the timepoints belonging to either timeseries that are within the overlap, to create a vector of times that are in either.
After that it interpolates the data that is within the overlap to the join time. This will exactly preserve any value that is within the series, interpolating only for the times that are in the other but not in this one.
You can proceed in different shorter ways, but if you do then you might well run into the situation where there are times that are in one but that are outside the range of the others. When you combine all of the times and ask to interpolate, those times outside would be requests to extrapolate instead of interpolate, and the default in such cases is to return NaN. You can deal with NaN in root mean squares if you are aware it might be there.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!