필터 지우기
필터 지우기

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

채택된 답변

fred  ssemwogerere
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
Lucas Acuna Scafati
Lucas Acuna Scafati 2020년 2월 11일
Thank you very much that worked perfectly.
One more question...
What is "C" or by that did you mean "Z"?
% The unique serial numbers are stored in "C".
[Z,mX,mY]=unique(T.SerialNumber);
fred  ssemwogerere
fred ssemwogerere 2020년 2월 12일
Hello, oh yes, by "C", i meant "Z". That was a typing error. Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by