Interpolation of two Matrices of different Lenght

2 views (last 30 days)
Hallo,
I am looking for a solution for my problem to "account" two Matrices of different Lengths.
I have two Sensors which have differnet Sampling Rates, so the Matrices with the Measurements have different lengths. Now I want to plot theses two Matrices in one Plot. The Problem is that in Matlab the Vetors must have the same Length to plot them together. I used the "downsample"-function to get the two Matrices to the same Length, but I don't like it because with this Method I loose many measured Values.
I would like to use a function like "interp1" (interp1 doesn't work either because of the different length of the matrices) so my programm doesn't skip any measured values.
Do you know a Matlab-function which can help me with my Problem? Thanks

Answers (1)

José-Luis
José-Luis on 29 Jan 2014
t1 = 1:20;
t2 = 1:2:20;
data1 = rand(numel(t1),1);
data2 = rand(numel(t2),1);
%One alternative
figure(1)
plot(t1,data1,t2,data2);
%Another
figure(2)
plot(interp1(t1,data1,t2),data2,'ro');
hold on
plot(get(gca,'Xlim'),get(gca,'XLim')); %1:1 line
%Yet another
figure(3)
plot(interp1(t2,data2,t1),data1,'ro');
hold on
plot(get(gca,'Xlim'),get(gca,'XLim')); %1:1 line

Community Treasure Hunt

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

Start Hunting!