How to match two matrices in time while having different sizes?
Show older comments
I am having two matrices each with one column and both having the same starting and ending points (for example, t=0 and t= 500). However, each one of them have different increments and hence the sizes differ. I want to match the two matrices with respect to these starting and ending points even if I loss some data points in between. I have tried the "ismember" command but this one is used to find the similarities for each value in the matrix while I want to match the positions rather than the values of the matrix. Any suggestions?
Answers (2)
Image Analyst
on 26 Jun 2016
0 votes
What does that mean exactly? Can you give a small example? For now, all I can suggest is to find out which vector is longer and then use splines to "fill in" the "missing" locations on the shorter vector. This will create values in between the common values while making sure your "knot" values (values in common) are in the same location in both vectors. I attach a spline example, though since it's an existing demo it needs some tweaking to do what you're asking.
14 Comments
M
on 26 Jun 2016
M
on 26 Jun 2016
Image Analyst
on 26 Jun 2016
OK, this is my third request (it might be my last): "Can you give a small example?"
Include both input arrays and what you'd like to see in your output.
M
on 26 Jun 2016
Edited: Image Analyst
on 26 Jun 2016
Image Analyst
on 26 Jun 2016
I don't understand. You gave code that actually does run. Is that B not what you want? How does your code damage "the accuracy and usefulness of the data"??? If that B is no good, then what would you like for B?
M
on 26 Jun 2016
Image Analyst
on 26 Jun 2016
M
on 26 Jun 2016
Image Analyst
on 26 Jun 2016
I'm getting lost. I see no reason why there should be little wiggles in the plot. Please post your entire script so we can examine it.
M
on 26 Jun 2016
Image Analyst
on 26 Jun 2016
That code does not make any plots. Please post the code you used. Also, I think you want to plot load vs. strain or vice versa. Yet all your commented out plot lines do is plot versus the index along the x axis. Why would you want to do that? What do you want to be along the x axis (load or strain), and what do you want to be along the y axis (load or strain)?
M
on 26 Jun 2016
Image Analyst
on 26 Jun 2016
I don't understand why you don't have a load for every strain value. Why don't they match up? Since they don't, what load values were being applied when the stain values were applied? You can't just say that you have 37 load values and 25 strain values without knowing what strain and load pairs match up. I mean, there are 12 extra load values, so WHERE did they come from? What strain was in effect when those load values were measured?
M
on 26 Jun 2016
dpb
on 26 Jun 2016
Not clear what you intend, precisely, no...but--
If you're meaning to pick points from the more densely populated that correspond to the same relative position in the shorter, then if you have Signal Processing Toolbox given
x=shorterSignal;
y=longerSignal;
ynew=resample(y,length(x),length(y),0); % resample y to same length as x
W/O the Toolbox it's about as simple--
ynew=interp1(1:length(y),y,1:length(x),'nearest'); % pick nearest integer index
3 Comments
Image Analyst
on 26 Jun 2016
As an example:
shorterSignal = [1, 4, 100, 500]
longerSignal = [2, 4, 100, 200, 317, 431, 457]
x=shorterSignal;
y=longerSignal;
ynewTB = resample(y,length(x),length(y),0) % resample y to same length as x
ynewNoTB =interp1(1:length(y),y,1:length(x),'nearest') % pick nearest integer index
Produces:
shorterSignal =
1 4 100 500
longerSignal =
2 4 100 200 317 431 457
ynewTB =
2 100 317 431
ynewNoTB =
2 4 100 200
Is this what is wanted? Hence the need to clarify the request with sample input and output data.
M
on 26 Jun 2016
dpb
on 26 Jun 2016
Don't know...what do you mean, precisely? Show an example...
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!