Calculating average and standard deviation for element correction factor from excel file
2 次查看(过去 30 天)
显示 更早的评论
I'm importing data from an excel file. I need to take the average of every of every serial number, then calculate the standard deviation percentage of every serial number. Any ideas how i could do that? Thank you
0 个评论
采纳的回答
fred ssemwogerere
2020-2-7
Hello, this should do nicely;
% Assuming your spreadsheet file is in the current (working) Matlab folder
optns=detectImportOptions('file.xlsx'); % replace the input "file.xlsx" here with the name of your file and extension
% Set variables to import from your file and import as table
optns.SelectedVariableNames={'SerialNumber','RawCounts'};
T=readtable('file.xlsx',optns); % replace "file.xlsx" with the name of your file
% Determine unique serial numbers and corresponding indices
% The unique serial numbers are stored in "C".
[Z,mX,mY]=unique(T.SerialNumber);
% Compute the mean for each unique serial number
avg=accumarray(mY,T.RawCounts,[],@mean);
% Compute the standard deviation for each unique serial number
stdev=accumarray(mY,T.RawCounts,[],@std);
% To calculate the percentage standard deviation or relative deviation, you
% multiply each standard deviation by 100, and divide it by its
% corresponding mean value in array; "avg".
percentdev=(stdev.*100)./avg;
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!