- readtable
- readmatrix
- mean, movmean (not sure how their time points will be used for averaging)
- interp1
averaging and interpolating random number of rows of data
1 view (last 30 days)
Show older comments
Hello, I have a list 800 particles data in an excel file. A total of 174755 rows...
Is there a way to extract these values and then average them based on their time point, later interpolate them based on the time point. I would like to average the first row of every particle 1,2,3....800. So after NaN, it will consider that as row 1,2,3...last number before NaN, then another row 1 again.
For example:
row 1 1 5
row 2 2 6
row 3 3 7
NaN
NaN
NaN
row 1 4 8
row 2 5 9
row 3 6 10
row 4 10 11
NaN
NaN
NaN
row 1 7 1
row 2 8 2
row 3 9 3
So the desired output average should be:
average of row 1 4 4.67
average of row 2 5 5.75
average of row 3 6 6.67
average of row 4 10 11
filename = 'plottemperature.xlsx';
T = xlsread(filename); %read excel file
[rows,columns] = size(T); %List the number of rows and columns
nanLocations = isnan(T); %declare all NaN locations in the excel file
for row = 1: rows
for col = 1:columns
if ~nanLocations(row,col) %I wanted to write it so that after the 3rd NaN it will be another row 1
%I am not sure how to continue from here to set the rows after every NaN as row 1 and then average all row 1
Please guide me. Thank you very much!
4 Comments
Adam Danz
on 29 Sep 2020
Unless you're using an old version of matlab, you sould not use xlsread. Instead, use one of the other functions recommended in the documentation. See the top of this page.
I didn't follow your averaging example. I can't imaging what would produce an avg of 4, for example.
Answers (1)
Image Analyst
on 29 Sep 2020
Yes, try this (untested):
badRows = isnan(T{:, 1}); % Find nans in column 1.
T = T(~badRows, :); % Extract all rows except the bad rows.
3 Comments
Image Analyst
on 30 Sep 2020
Not sure I understand your new question. Please give an example input table and output table.
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!