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

2 Ansichten (letzte 30 Tage)
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 Kommentare
Image Analyst
Image Analyst am 21 Jun. 2022
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 am 21 Jun. 2022
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Maneet Kaur Bagga
Maneet Kaur Bagga am 1 Sep. 2023
Bearbeitet: Maneet Kaur Bagga am 1 Sep. 2023
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

Weitere Antworten (0)

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by