splitting periodic data using cellarray

조회 수: 2 (최근 30일)
Samar Bahman
Samar Bahman 2021년 6월 4일
댓글: Star Strider 2021년 6월 5일
Hi,
I have a set of data which is periodic and in each period there is an ascending behaviour. I would like to split this data into sets of only ascending data using a cell array. My code has been successful in creating the first set in the first row of the cell array. My question is: how can I continue with the loop and write the data on the second row of the cell array?
Thanks for your help in advance :)
Here is my code:
auxArray={};
for j=2:1:size(newV_ch)
if newV_ch(j)-newV_ch(j-1)>0
auxArray{end+1}=newV(j);
else
break
end
end

채택된 답변

Star Strider
Star Strider 2021년 6월 5일
The actual result depends on the signal (that may need to be filtered if it is noisy), however the code would be something like this —
t = linspace(0, 50, 500); % Time Vector
y = sin(2*pi*t/10); % Signal Vector
[pks,locsp] = findpeaks(y); % Find Maxima & Indices
[vls,locsv] = findpeaks(-y); % Find Minima & Indices
pkidx = sort([locsv locsp(locsp > locsv(1))]); % Edit & Sort Indices
for k = 1:2:numel(pkidx)-1
idxrng = pkidx(k):pkidx(k+1); % Index Range For Each Segment
tv{k} = t(idxrng); % Corrseponding Time Vector
Asc{k} = y(idxrng); % Corresponding Signal Segment Vector
end
figure
plot(t, y) % Plot Original Signal
hold on
for k = 1:numel(tv)
plot(tv{k}, Asc{k}, '-r', 'LineWidth',2) % plot Results
end
hold off
grid
It should be relatively straightforward for you to adapt this to your signal.
  댓글 수: 6
Samar Bahman
Samar Bahman 2021년 6월 5일
Thank you very much! It was a big help :)
Star Strider
Star Strider 2021년 6월 5일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by