Can someone explain to me how this function works?

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 :)

댓글 수: 2

Explain what?
Just in normal language how the function calculates the next temperature for a single cell in the fin array.

댓글을 달려면 로그인하십시오.

 채택된 답변

Roger Stafford
Roger Stafford 2014년 11월 18일

1 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

질문:

2014년 11월 17일

답변:

2014년 11월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by