Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Making Vectors of data from time series

1 visualizzazione (ultimi 30 giorni)
XGidley
XGidley il 24 Mag 2020
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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 Commenti
XGidley
XGidley il 28 Mag 2020
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 il 28 Mag 2020
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.

Risposte (1)

Maadhav Akula
Maadhav Akula il 31 Mag 2020
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!

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by