How to increase elements of a vector, of different size, without changing its plot?

4 vues (au cours des 30 derniers jours)
I have several matriz (sample) of diferente size. Each matriz contain 2 columns.The first column contains the axis (labels) indicating the range and the resolution and the second column the data. The recorded axis are different for each matriz (sample) and i need to synchronize this data.
Is it possible to do it? I tried to use interp1 but without success.
The data for 2 samples is attached.
  1 commentaire
Akira Agata
Akira Agata le 12 Nov 2019
Question is not clear for me...
Looking at your data, both 1st and 2nd column are numeric. By simply plotting the data, the following plot was obtained.
You mean, you want to apply "resampling" for both a and b with the same sampling timing?
ab.png

Connectez-vous pour commenter.

Réponse acceptée

Akira Agata
Akira Agata le 13 Nov 2019
OK.
Then, I would recommend converting your data into timetable, and applying synchronize and/or retime function.
The following is an example.
% Load your data
load('data.mat');
% Create timetable by assuming 1st column is time in [s]
Time = seconds(a(:,1));
A = a(:,2);
ttA = timetable(Time,A);
Time = seconds(b(:,1));
B = b(:,2);
ttB = timetable(Time,B);
% Synchronize these two data
ttAll = synchronize(ttA,ttB);
% Fillign NaN by applying interpolation, if needed
ttAll = fillmissing(ttAll,'linear');

Plus de réponses (2)

Licarion Pinto
Licarion Pinto le 12 Nov 2019
Firstly, thanks for your help.
Exactly. I need to "resample" all my data in a way that the time (column 1) and the number of variables are equal. I have aproximatly one hundred samples. I tried the following command to interpolate:
C = {a, b};
S1 = min(cellfun('size', C, 1));
S2 = min(cellfun('size', C, 2));
D = cell(size(C));
for k = 1:numel(C)
siz = size(C{k});
D{k} = interp2(C{k}, linspace(1, siz(2), S2).', linspace(1, siz(1), S1));
end
It solves the problem of having the same number of variables. But, the times (column 1) were not equal.
If it is possible, it would be interesting for me to have the time range equal to the longest range (from the shortest to the longest time) and for the missing time value use NaN so the number of variables and the range in column 1 will be the same.
The critical for me is that all data in column 2 are the same for all samples, ie the time (column 1) match for all samples.
Thank you for your help in advance,
best regards,
Licarion

Licarion Pinto
Licarion Pinto le 13 Nov 2019
It works perfectly.
Thanks a lot.

Catégories

En savoir plus sur Functions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by