Storing Live streamed data

22 ビュー (過去 30 日間)
BionicP
BionicP 2021 年 1 月 30 日
コメント済み: BionicP 2021 年 2 月 6 日
Hi, so i am currently working on a project which is taking streamed data from a device to matlab. Now i am using this data to control a prosthesis but i am struggling to write some code that will store the data in an appropriate variable that can run classification (Machine learning) on the data. I have 4 channels worth of data, and the easiest part of this is i dont even need all the data saved, just the most significant feature i.e. only above a threshold.
The streamed data is coming in at a rate of 2000Hz but as i said before i only need the values after the thresholding. I simply am struggling with storing this data, the threhsold is of course easy. I dont know the size of the data to create as its live data which is a problem in itself (Not being able to run machine learning on the whole data).
I have been trying this for a while, if anyone can help it would be greatly appreciated.

採用された回答

dpb
dpb 2021 年 1 月 30 日
編集済み: dpb 2021 年 1 月 30 日
Open a file before beginning the process and write whatever it is that is wanted...formatted data is simple to read but bulky, stream data is compact and the fastest way...not having been given any of your code variables can't try to fit into whatever it is you do have, but the idea is
fid=fopen('LoggingFile.dat','w');
collecting=true;
while collecting
x=readdatafromsource;
y=threshold(x);
fwrite(fid,y,'double')
end
fid=fclose(fid);
The above presumes some other manner such as a pushbutton callback that sets the variable collecting to false to stop the collection process; you've apparently got all that worked out already.
Then just
fid=fopen('LoggingFile.dat','r');
data=fread(fid);
fid=fclose(fid);
will give you the saved data in a 2D array, assuming the x data are a 4-vector as described for each collection cycle.
ADDENDUM:
Alternatively, if you have sufficent memory, hold the data in memory and use a .mat file at the end.
  8 件のコメント
dpb
dpb 2021 年 2 月 6 日
This is tougher for us to help with; we don't have the means to run the code so you've got to do the heavy lifting. We can give advice or answer syntax errors or even help diagnose further symptoms, but that's about all...
BionicP
BionicP 2021 年 2 月 6 日
No of course, i think you have helped alot anyways haha but if i do come across further issues pertaining to this part, ill try ask and see if you can help! For now though, i should be able to go from here or atleast with the idea you have given me !!
Once again, Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by