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!