Finding the averages for a unique text value
1 vue (au cours des 30 derniers jours)
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
0 commentaires
Réponses (2)
Dyuman Joshi
le 2 Nov 2022
2 commentaires
Dyuman Joshi
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)
Voss
le 2 Nov 2022
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
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!