Clear Filters
Clear Filters

Can someone explain to me how this function works?

1 view (last 30 days)
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 Comments
Andrew Ardolino
Andrew Ardolino on 17 Nov 2014
Just in normal language how the function calculates the next temperature for a single cell in the fin array.

Sign in to comment.

Accepted Answer

Roger Stafford
Roger Stafford on 18 Nov 2014
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.

More Answers (0)

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!