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
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:
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!