Calculate the difference of two vectors with different lengths
6 views (last 30 days)
Show older comments
Hello everyone, I want to compare experimental data with analytical solutions. I have 4 vectors:
- Experiment: Time from 0 to 2s, Velocity - Those vectors have a length of 400
- Analytical solution: Time from 0 to 0.7s, Velocity - Those vectors have a length of 60
I can only compare in the interval of [0-0.7] so I cut my first Vector at 0.7s and have a new length of 170. Now I want to get the difference between those two data sets, one with 170 entries and one with only 60.
My first idea was to use interp1 and reduce the 170 vector down to 60. After taking a look at the result, this turned out to be very inaccurate at some points. Any ideas how I could do better?
Thank you very much
1 Comment
KSSV
on 8 Jun 2017
The time steps of your experiment and analytical are same? Actually interp1 should work. YOu have analytical solution, you can adjust the time step of it, so that it gives same dimension as the experimental one.
Accepted Answer
Star Strider
on 8 Jun 2017
First, if you have an analytical expression, can’t you simply evaluate it at the same times you sampled your signal? It should be relatively straightforward to program that in MATLAB.
Second, a more reliable way of interpolating a signal is the Signal Processing Toolbox resample function. You can give it specific values of your independent variable to interpolate your 0 to 0.7 seconds vector. (You need to read through the documentation for this. It’s not hidden, but not obvious.)
Also, you must compare only the values at the times that match.
0 Comments
More Answers (0)
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!