How do I average a matrix in steps but they are not all in equal steps
1 次查看(过去 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!