Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Making Vectors of data from time series

조회 수: 1 (최근 30일)
XGidley
XGidley 2020년 5월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
This has likely been asked several times, I'm just not asking it in the right way to find all the other answers. SO thank you for your patience.
I have a cycle of data where the signal is on and then off for 10 seconds. How do I extract the data that represents ON and put that into new vectors? So from one time series I end up with 10 vectors.
  댓글 수: 3
XGidley
XGidley 2020년 5월 28일
Sure. Attached is a simple data time series with three sine waves back to back. What I want is to load the data as it is in MATLAB; the whole series. But find the three sine waves (not based on time, based on a characteristic of the sine wave - crossing the x-axis, for example), so I can run my analysis on each of the three separately and call them out as trial one, two and three. I do not want to average them together just yet. I need to analyze them separately and save them separately.
I'm just trying to eliminate the arduous task of separating the trials (or sine waves in this case) by hand and making separate data files and read them in separately to Matlab. So I see this as a data handling issue. In all my other work I have read in discrete trials, but as I'm getting into capturing cyclic data for 10 seconds or so I want to opperationalize the separation of trials (or the sine waves in my example).
Thank you for your help
Brent Kostich
Brent Kostich 2020년 5월 28일
I would recommend using the "Import Data" tool from the MATLAB "Home" tab. This not only makes the import process simple, you can auto-generate code for future imports. Or of course you can hand code the import process. xlsread or readtable would be useful if you go the manual route.
In terms of data analysis, I think you pretty much have the main idea. Try using the find function to locate the index points at which the data crosses the x-axis, which based on your data is just zero. From there, use the indices to create seperate vectors from your original data set.

답변 (1개)

Maadhav Akula
Maadhav Akula 2020년 5월 31일
Hi,
As Brent pointed out you can use the find function to sove your problem, you can have a look at the following code:
pos = true;
a = 1;
b = 1;
pos_wave = cell(3,2);
neg_wave = cell(3,2);
while ~isempty(y)
if pos
k = find(y < 0, 1 ,'first');
pos_wave{a,1} = y(1:k-1);
pos_wave{a,2} = t(1:k-1);
y = y(k:end);
t = t(k:end);
a = a + 1;
pos = 0;
else
k = find(y > 0, 1 ,'first');
neg_wave{b,1} = y(1:k-1);
neg_wave{b,2} = t(1:k-1);
y = y(k:end);
t = t(k:end);
b = b + 1;
pos = 1;
end
end
where y and t are the values of Sinewave and time respectively from the provided Excel Sheet.
Hope this helps!

태그

Community Treasure Hunt

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

Start Hunting!

Translated by