How do I average a matrix in steps but they are not all in equal steps

조회 수: 2 (최근 30일)
I have a matrix of 2214 by 8001, the absorbances were measured 5 times for each sample but some signals were were not good enough so they were removed during data cleaning. Now the matrix is left with 3, 4 or 5 signals per sample. They are no longer all 5 signals per sample. I need help with a code to create an average matrix.....xxx by 8001 since I cannot use reshape for this particular problem.
Thank You
  댓글 수: 3
Image Analyst
Image Analyst 2022년 6월 21일
What do the rows and columns of your matrix represent? Do you have 3, 4, or 5 of those matrices?
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
NCA
NCA 2022년 6월 21일
Apologies, if my question was not clear.
The matrix contains 2214 rows by 8001 coloums
Each sample measurement is repeated 5 times but I have removed some bad ones now I am left with some samples with only 3 or 4 runs. I need a code to average the samples. I cant use reshape because they are not in equal steps of 5 any longer.If it helps see below representation using 11 rows of imaginary samples
Sample 1
Sample 1
Sample1
Sample 2
Sample 2
Sample 2
Sample 2
Sample 2
Sample 3
Sample 3
Sample 3
Sample 3
etc etc

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

채택된 답변

Maneet Kaur Bagga
Maneet Kaur Bagga 2023년 9월 1일
편집: Maneet Kaur Bagga 2023년 9월 1일
Hi @NCA
As per my understanding of the question, when the data cleaning is being done and followed by this we want to do data labelling we can use the following approach:
  • Create a table where each row is labelled to which sample it belongs
  • Extract all the signal values related to a particular sample
  • Then calculating the average of above we get the average signal value and store it in an array
You may refer to the below code for the understanding of above steps:
rng(0);
xdata = randi([0 10], 5,3);
sample_no = [1 1 2 2 2]';
% creating a table at the time of data cleaning.
t = table(xdata,sample_no,'VariableNames',[ "Data", "SampleNo"]);
disp("table");
display(t)
unique_samples = unique(t.SampleNo); % Unique signals
avgSignals = zeros(numel(unique_samples), 3); %to store the average signal values.
for i = 1:numel(unique_samples)
data_for_sample_i = t{t.SampleNo == i, "Data"}; %extracting signal values that belong to sample i.
average = mean(data_for_sample_i,1); %taking mean of the extracted signal values.
avgSignals(i,:) = average;
end
disp("average signal values");
disp(avgSignals);
You may refer to the following documentation for better understanding
Table:
Data Cleaning and Calculations in Table:
I hope this helps!
Thank You!
Maneet Bagga

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by