How do I average a matrix in steps but they are not all in equal steps
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
NCA
le 21 Juin 2022
Modifié(e) : Maneet Kaur Bagga
le 1 Sep 2023
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 commentaires
Image Analyst
le 21 Juin 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:
Réponse acceptée
Maneet Kaur Bagga
le 1 Sep 2023
Modifié(e) : Maneet Kaur Bagga
le 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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!