現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
So I wanted to split the 1X15 cell to different cells.
2 ビュー (過去 30 日間)
古いコメントを表示

Yes this is a screenshot of a screenshot.
So I have a 1x15 cell
Each (cell)column is one channel so a total of 15 channels.
2nd screenshot is a 1st channel with 2 states.
So now i wanted to put each state of one channel into a seperate matrix or a cell(preferably a cell).The state changes from rest to active every 200th iteration and vice versa.
So new cell of channel 1 would contain 1 cell for with values for rest block and next cell for active block and so on.
so repeat this for 15 channels.
I have attached mat file of my data.
3 件のコメント
Guillaume
2019 年 9 月 18 日
編集済み: Guillaume
2019 年 9 月 18 日
What do you want to do with that data?
Personally, I'd go the other way, and put everything into one table with 3 columns: Channel, hBo, state
Most likely, whatever it is you want to do will be easier with just one table than cell array of cell arrays of cell arrays.
CalebJones
2019 年 9 月 18 日
I wanted to split it because i wanted calculate mean,slope,kurtosis,peak which i will use as my feature set for training my model.
採用された回答
Guillaume
2019 年 9 月 18 日
If you want to perform group statistics, the simplest is indeed to put everything in just one table:
allresults = vertcat(result{:}); %concatenate everything into one table
allresults.channel = repelem((1:numel(result))', cellfun(@height, result)); %and add a channel column
stats = groupsummary(allresults, {'state', 'channel'}, {'mean', @kurtosis}); %not sure what you mean by slope and peak
20 件のコメント
CalebJones
2019 年 9 月 19 日
Doesn't do what i expected it to do.
Thanks anyways.
appreciate if you could be me out further.
Guillaume
2019 年 9 月 19 日
appreciate if you could be me out further
Clearly, I haven't understood what you want, so I need more details in order to help further.
CalebJones
2019 年 9 月 19 日

If you have a look at this image. Like wise even i have extracted HbO which is oxy hemoglobin and HbR which is deoxy Hemoglobin.
And in my dataset is a task like rest active above image shows rest and tap.
Above image plots only 1 channel signal , likewise there at 15 channels.
My dataset(attached above) has calculated HbO Values and labeled things as rest and active for each channel.
So now i wanted to train my model such that it predicts rest and active states with decent accuracy using features like slope,mean,kurtosis,skewness,etc.
Guillaume hope now you get a gist of whats happening?
Thank you
Guillaume
2019 年 9 月 19 日
If it's stat per each rest and active period you want, then you simply need to add another variable to identify each of these period:
%this is as before:
allresults = vertcat(result{:}); %concatenate everything into one table
allresults.channel = repelem((1:numel(result))', cellfun(@height, result)); %and add a channel column
%now add a variable whose value is identical for each continuous rest/active period:
allresults.eventid = cumsum([1; diff(findgroups(allresults.state)) ~= 0]);
You can now use that variable for grouping:
stats = groupsummary(allresults, {'state', 'channel', 'eventid'}, {'mean', @kurtosis}); %not sure what you mean by slope and peak
You can specify your own statistical function to pass to groupsummary. It will be called once for each distinct group, with the HbO vector of values for each group.
CalebJones
2019 年 9 月 19 日
It will be called once for each distinct group, with the HbO vector of values for each group.
Could you elaborate with an example?
Is it like @kurtosis_allresult would call---> kurtosis_allresult = kurtosis(allresult,0,'all');
Similarly...
Skweness_allresult = skewness(allresult);
slope_allresult = diff(allresult);
Guillaume
2019 年 9 月 19 日
編集済み: Guillaume
2019 年 9 月 19 日
No, I've given you an example above:
stats = groupsummary(allresults, {'state', 'channel', 'eventid'}, {'mean', @kurtosis}); %not sure what you mean by slope and peak
Since I don't have the stats toolbox (with kurtosis), I can't show you the result for that, but here is an example with a made-up function:
function s = slope(values)
%fit a linear polynomial to the data, and return the slope of the line
if ~isempty(values)
p = polyfit(1:numel(values), values', 1);
s = p(1);
else
s = NaN;
end
end
and using it on your data:
%merge all into one table with extra columns:
allresults = vertcat(result{:}); %concatenate everything into one table
allresults.channel = repelem((1:numel(result))', cellfun(@height, result)); %and add a channel column
allresults.eventid = cumsum([1; diff(findgroups(allresults.state)) ~= 0]);
%get stats: mean and slope
stats = groupsummary(allresults, {'state', 'channel', 'eventid'}, {'mean', @slope}); %not sure what you mean by slope and peak
stats.Properties.VariableNames{end} = 'slope_HbO'; %better variable name that what matlab autogenerate
head(stats) returns:
>> head(stats) %first 8 rows
ans =
8×6 table
state channel eventid GroupCount mean_HbO slope_HbO
______ _______ _______ __________ _________________ ___________________
active 1 2 200 -7.67231127895478 -0.091165802772305
active 1 4 200 35.5962270614642 0.076534807760347
active 1 6 197 -19.7591859046008 0.252152452160729
active 2 8 200 -15.9692390786319 0.235640586381289
active 2 10 200 20.5796697869384 -0.0664683822345007
active 2 12 197 -17.5921264661321 0.200172452731579
active 3 14 200 7.17042032876279 -0.0507776796191182
active 3 16 200 12.637946834818 -0.218112096344478
CalebJones
2019 年 9 月 20 日
Guillaume Thanks a lot....
But one question why are channels repeating? number of Rest and Active per channel add up to the correct value which is 1197 which is correct.
But could you explain why ?
CalebJones
2019 年 9 月 20 日
編集済み: CalebJones
2019 年 9 月 20 日

Okay say i used only mean and slope for training i should be excluding eventid and channel right?
Obvioulsy state should be my response (rest or active).
And run the classifier with Groupcount, mean and slope right?
Guillaume
2019 年 9 月 20 日
why are channels repeating
You get one row per unique combination of channel, state and eventid.
With regards to the classification, I'm afraid I can't help with that, I don't have the toolbox. If you don't care which channel the data come from, I assume you should remove it from the classification. You obviously don't care about the eventid anymore, its only purpose was to allow grouping into consecutive identical states.
CalebJones
2019 年 9 月 20 日
I analysed it step by step.Now it makes sense.Your a genuis mate.
I was looping to do all this and it was driving me nuts.Your code was just consise and to the point.
CalebJones
2019 年 9 月 23 日
I was calculating variance and its throwing this error----
stats = groupsummary(allresults, {'state', 'channel', 'eventid'}, {'mean', @slope_HbO,@variance_HbO});
the function variance_HbO contains this----
function vari = variance_HbO(values)
%fit a linear polynomial to the data, and return the slope of the line
if ~isempty(values)
v = var(1:numel(values), values', 1);
vari = v(1);
else
vari = NaN;
end
error-------
Error using groupsummary (line 522)
Unable to apply method 'fun2' to data variable HbO.
Caused by:
Error using var (line 192)
W must be a vector of nonnegative weights, or a scalar 0 or 1.
Guillaume
2019 年 9 月 23 日
You don't need a separate function for that. var is supported by groupsummary:
stats = groupsummary(allresults, {'state', 'channel', 'eventid'}, {'mean', @slope_HbO, 'var'});
Unless you do want a weight of 1. In which case if you use a separate function it's as simple as:
function vari = variance_hBO(values)
vari = var(values, 1);
end
You could also use an anonymous function
stats = groupsummary(allresults, {'state', 'channel', 'eventid'}, {'mean', @slope_HbO, @(v) var(v, 1)});
CalebJones
2019 年 9 月 23 日
Thanks that worked...
I was trying to include peak as well.
stats = groupsummary(allresults, {'state', 'channel', 'eventid'}, {'mean', @slope_HbO, @(v) var(v, 1), @(p) findpeaks(p)});
but it was throwing an error,
Error using groupsummary (line 522)
Unable to apply method 'fun3' to data variable HbO.
Caused by:
Error using findpeaks
Expected Y to be nonempty.
If I try k = findpeaks(allresults.HbO); then size of k is 229x1 so will that be an issue while grouping?Is there a way around this ?
Guillaume
2019 年 9 月 23 日
You have two issues there.
As an implementation detail, groupsummary first call the function with an empty vector (not sure why) and findpeak doesn't like that. That's the error you're getting.
The second issue is that groupsummary wants scalar output out of the function and that's not going to be the case with findpeaks.
You could fix both problems with this function (untested):
function out = my_findpeaks(values)
if isempty(values) %function may be called with empty vector by groupsummary, which is a problem for findpeaks
out = {}; %return scalar cell with nothing in it
else
out = {findpeaks(values)}; %wrap output of findpeaks in a scalar cell
end
end
But do you really want to return all the peaks? it may be better to extract just one or two peaks from the data in the above function.
CalebJones
2019 年 9 月 23 日
function out = my_findpeaks(values)
if isempty(values) %function may be called with empty vector by groupsummary, which is a problem for findpeaks
out = {}; %return scalar cell with nothing in it
else
out = {findpeaks(values)}; %wrap output of findpeaks in a scalar cell
end
end
Unfortunatly, this doesn't work.
And yes perhaps one or two peaks would be better than all.
CalebJones
2019 年 9 月 23 日
Error using groupsummary (line 522)
Unable to apply method 'fun3' to data variable HbO.
Caused by:
Error using findpeaks>parse_inputs (line 206)
Data set must contain at least 3 samples.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)