Creating a matrix of standard deviation values
2 次查看(过去 30 天)
显示 更早的评论
I have 2 124x173 matrixes that I am trying to produce standard deviation matrixes for each of them. I would like to take the standard deviation of each element of the matrix and then create a new matrix of each standard deviation value of the same size. So in the end I have two new 124x173 matrixes consisting of the standard deviation values.
I have tried using std() function however this only returns a row vector I believe. When I have tried reshape this vector to 124x173 I get error "To reshape the number of elements must not change."
I have attached the code below most of it can be ignored for this problem however I will attach it all for a more full scope of what I am doing.
A=dlmread('B00001.txt', '',1,0); %Read first file
for k=2:100;
A=A+dlmread(['B00',sprintf('%03d.txt',k)], '',1,0); %Sum all Matrixes
end
A=A/100; %Average Matrixes
X = reshape(A(:,1),124,173); %Reshape all matrixes
Y = reshape(A(:,2),124,173);
U = reshape(A(:,3),124,173);
V = reshape(A(:,4),124,173);
AverageU=mean(nonzeros(U)) %Average Streamwise Velocity
AverageV=mean(nonzeros(V)) %Average Wall Velocity
stdU=std(U);
stdV=std(V);
pcolor(X,Y,U); %Contour Plot of Streamwise Velocities
hold on
shading interp
colormap(jet);
h = colorbar;
ylabel(h, 'm/s')
xlabel('x(mm)')
ylabel('y(mm)')
pause
pcolor(X,Y,V); %Contour plot of Wall Velocities
hold on
shading interp
colormap(jet);
h = colorbar;
ylabel(h, 'm/s')
xlabel('x(mm)')
ylabel('y(mm)')
pause
pcolor(X,Y,stdU); %Standard Deviation Contour plot of U
hold on
shading interp
colormap(jet);
h = colorbar;
ylabel(h, 'm/s')
xlabel('x(mm)')
ylabel('y(mm)')
pause
pcolor(X,Y,stdV); %Standard Deviation contour plot of V
hold on
shading interp
colormap(jet);
h = colorbar;
ylabel(h, 'm/s')
xlabel('x(mm)')
ylabel('y(mm)')
0 个评论
回答(1 个)
Image Analyst
2020-5-2
You need to use stdfilt() to take the standard deviation of all values in a certain neighborhood around each element:
windowSize = 5
stDevMatrix = stdfilt(A, ones(windowSize));
It requires the Image Processing Toolbox.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!