MATLAB Answers

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

1 view (last 30 days)
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 Comment

Akira Agata
Akira Agata on 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

Sign in to comment.

Accepted Answer

Akira Agata
Akira Agata on 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');

  0 Comments

Sign in to comment.

More Answers (2)

Licarion Pinto
Licarion Pinto on 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

  0 Comments

Sign in to comment.


Sign in to answer this question.