Finding the averages for a unique text value
古いコメントを表示
I have an excel document with data as below, I wish to obtain the (edit: mean and standard error) for column 6/F (RingSpotTotalIntenCh2) per unique identifier in Column 1/A. I have tried the following:
[~,~,dat]=xlsread(Target_filepath);
X=[dat(:,1) dat(:,6)];
mat = cell2mat(cellfun(@(V)accumarray(X(:,1),V,[],@mean),num2cell(X,1),'UniformOutput',false));
But AccumArray does not seem to like that Column 1/A is not a number:
Error using accumarray
Cells of first input SUBS must contain real, full, numeric vectors of equal length.
Error in ZaniaSpikeProteinIntensity>@(V)accumarray(X(:,1),V,[],@mean)
Error in ZaniaSpikeProteinIntensity (line 13)
mat = cell2mat(cellfun(@(V)accumarray(X(:,1),V,[],@mean),num2cell(X,1),'UniformOutput',false));
Is this possible? Edit: is it also possible to keep the identifiers (column 1) with the means?
Thanks

回答 (2 件)
2 件のコメント
Adam McGuinness
2022 年 11 月 2 日
Yes, you can see that output from unique() function call.
(The first output from unique can also be utilized in calling accumarray, as you can see it here in while calculating the mean)
y=readtable("data.xlsx", "VariableNamingRule","preserve")
[a,~,c]=unique(y.Well)
indmean=accumarray(c,y.RingSpotTotalIntenCh2,[numel(a) 1],@mean)
I guess you mean standard deviation, and yes, it can be calculated as well.
indstd=accumarray(c,y.RingSpotTotalIntenCh2,[],@std)
Target_filepath = 'Eg data.xlsx';
[~,~,dat]=xlsread(Target_filepath)
X = dat(2:end,[1 6])
mat = accumarray(findgroups(X(:,1)),vertcat(X{:,2}),[],@mean)
1 件のコメント
Adam McGuinness
2022 年 11 月 2 日
編集済み: Adam McGuinness
2022 年 11 月 2 日
カテゴリ
ヘルプ センター および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!