Finding the averages for a unique text value
Afficher commentaires plus anciens
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

Réponses (2)
2 commentaires
Adam McGuinness
le 2 Nov 2022
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 commentaire
Adam McGuinness
le 2 Nov 2022
Modifié(e) : Adam McGuinness
le 2 Nov 2022
Catégories
En savoir plus sur Data Import from MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!