Averaging matrix values after Interpolation
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hey, I have a matrix that is 1x24. Within each cell is another matrix that is a single column. However, the column length changes from one matrix to another. Is there a way to average the first row from each matrix, and output into a new matrix where the first cell is the average of all the matrix first cells? Then second and third all the way to the end?
Here is my script so far. You can see that I create a matrix. Now I would like to average them (after I interpolate them).
close all
clear
clc
k = cell(1,2);
for k=1:24
data{k} = xlsread('C:\data.xlsx',['PKA', num2str(k)]);
end
for i=1:24
xfinal{i}=data{1,i}(end,1);
xi{i}=0:0.001:xfinal{i};
xi{i}=transpose(xi{i});
x{i}=data{1,i}(:,1);
y{i}=data{1,i}(:,4);
yi{i} = interp1(x{i},y{i},xi{i});
end
1 Kommentar
Antworten (1)
Jan
am 19 Jul. 2017
Which is the cell you want to average over? If it is yi:
v = zeros(1,24);
for k = 1:24
v(k) = yi{k}(1);
end
meanV = mean(v);
Now it matters what "Then second and third all the way to the end" exactly means, because the vectors have a different size. What is "end" then?
What about joining the vectors to a matrix and padding it with NaNs:
Len = cellfun('length', yi);
V = NaN(max(Len), 24);
for iC = 1:24
V(1:Len(iC), iC) = yi{iC};
end
Now you can uses nanmean or mean(V, 1, 'omitnan') to calculate the average.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!