I wanted to iterate this piece of code for 10 seconds.

9 ビュー (過去 30 日間)
CalebJones
CalebJones 2019 年 10 月 24 日
編集済み: CalebJones 2019 年 10 月 24 日
disp('Opening an inlet...');
inlet = lsl_inlet(stream_result{1});
[vec,ts] = inlet.pull_sample();
start = ts;
fNIRS_record = [];
flag = 0;
while ts - start < 1 %one second data which is ~8 frames
[vec,ts] = inlet.pull_sample();
fNIRS_record = [fNIRS_record;vec];
fprintf('%.2f\t',vec);
fprintf('%.5f\n',ts);
flag = flag + 1;
end
if(flag == size(fNIRS_record,1))
%Real time channel exclusion based on threshCV
RT_HbO = fNIRS_record( :,2:2:end);%getting only HbO values at real time
%using getCV() eliminate bad channels.
RT_vertcat = mean(RT_HbO,2);%avg of all 20 channels.
RT_vertcat = array2table(RT_vertcat);
realtime_stats_HbO = groupsummary(RT_vertcat,{}, {'mean', @slope_HbO, @(v) var(v, 1), @(pk) max(pk), @(sk) skewness(sk), @(kurt) kurtosis(kurt)});
clear flag;clear RT_HbO;clear RT_vertcat;
label = trainedModel.predictFcn(realtime_stats_HbO); %<--------------It has predict and print the label and clear everything and run the loop again for desired time period which is 10 seconds.
end

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 10 月 24 日
tic;
while toc < 10
Timing is unlikely to be exact.
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 10 月 24 日
for iter = 1 : 10
tic;
... do the work
pause(1-toc);
end
CalebJones
CalebJones 2019 年 10 月 24 日
編集済み: CalebJones 2019 年 10 月 24 日
It runs for one iteration and pauses for 10 seconds thats all.
See inlet = lsl_inlet(stream_result{1});
[vec,ts] = inlet.pull_sample();
start = ts;
Through inlet my data is continuos flowing in at real time.
ts is the start of frame.
I have make changes to start such that it iterates the way i want it to.
Basically i want to give it 10 seconds
while ts - start < 1 %one second data which is ~8 frames
Here it 1 second gives me 8 values and using groupsummary I am calculating statical features.
after which label = trainedModel.predictFcn(realtime_stats_HbO); using the statical feature i want run it through my model to predict a state.
Then i want to start fresh again ....till 10th second

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by