Can someone explain to me how this function works?

1 次查看(过去 30 天)
function finElemNext = nextTemps( finElem )
% This function will create a new fin element array by averaging the
% temperatures surrounding each element location
% uses finElemNext = nextTemps( finElem )
global maxDelta
maxDelta=0;
newFin=zeros(numRows,numCols);
for i = 2 : (numRows - 1)
for j = 2 : (numCols - 1)
t_original=finElem(i,j);
if t_original~=steamTemp
t_row_above=finElem(i-1,j);
t_row_below=finElem(i+1,j);
t_col_left=finElem(i,j-1);
t_col_right=finElem(i,j+1);
newFin(i,j)=mean([t_original,t_row_above,t_row_below,t_col_left,t_col_right]);
delta=finElem(i,j)-newFin(i,j);
if delta>maxDelta
maxDelta=delta;
end
else
newFin(i,j)=finElem(i,j);
end
end
end
finElemNext=setupFin(newFin);
end
I just need to be able to explain how this program calculates the data for this function. Thanks in advance :)

采纳的回答

Roger Stafford
Roger Stafford 2014-11-18
The complete 'nextTemps' function is not shown, so we are left guessing about some parts of it. For example we can only guess that 'numRows' and 'numCols' are the numbers of rows and columns of 'finElem'.
Each of the elements of 'finElem' which are not equal to 'steamTemp' and which are not along its borders are replaced in 'newElem' by the mean (average) of itself and its four nearest neighbors. Before 'setupFin' is called, the borders of 'newElem' are left as zeros. There is no way to tell what happens after 'setupFin' is called, but apparently the original border values of 'finElem' are permanently lost. A record is kept in 'maxDelta' of the maximum decrease occurring from 'finElem' to 'newElem', but this maximum does not appear to be returned by 'nextTemps'.
Taken all-in-all, this function, 'nextTemps', or at least its presentation here, is altogether unsatisfactory.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by