How to shift data sets automatically
古いコメントを表示
I have two sets of data that produce curves (see attached), and I want to analsye them both so need the data points to line up. Is there a code I can use to get Matlab to line up the data points for me? i.e the peak point for U should be the same data point as the one for D. The matrices are the same size but can be shortened if necessary to do this.
3 件のコメント
Vilém Frynta
2023 年 3 月 23 日
hi,
my approach to this problem would be:
- using max and find, find the highest value (peak) and it's position (index)
- using simple logic, find which maximum is "further" (which index is higher). then, find the difference between the distances of peak (difference in index numbers)
- using NaN, create vector full of NaNs, the length will be length of the original data + difference of the maximum indexes
- using indexing and knowledge about position of the peaks, insert your data into your NaN vector.
definitely would be doable and easier to show with code, if you attach your data. but, anyway, i hope my guidance was helpful to you.
Damaris Litton
2023 年 3 月 23 日
hello,
yes.
% load data
load U.mat
load D.mat
% make vectors from your data (previously columns)
U = U'
D = D'
% find maxs (peaks)
idx.U = find(U == max(U));
idx.D = find(D == max(D));
% difference between the peaks
idx.diff = idx.U - idx.D
% let's assume U is further
is_U_further = 1;
% find if D is further (if idx.diff is negative)
if idx.diff < 0
is_U_further = 0;
idx.diff = idx.D - idx.U % switch the difference in that case
end
% create NaN vector and new variables
L = length(U);
new.U = NaN([1 L+idx.diff]);
new.D = NaN([1 L+idx.diff]);
% fit the values so the peaks are at the same index
if is_U_further == 1; % if U is further... do this:
new.U(1:L) = U;
new.D(idx.diff:idx.diff+L-1) = D; % move D further, so it matches
end
if is_U_further == 0;% if D is further...
new.D(1:L) = D;
new.U(idx.diff:idx.diff+L-1) = U;
end
plot(new.U)
hold on
plot(new.D)
thought i did it wrong but it looks like "D" is just too small (no pun intended). you can try to strech that or make new, relative Y axis for it.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

