Can someone explain to me how this function works?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Andrew Ardolino
el 17 de Nov. de 2014
Respondida: Roger Stafford
el 18 de Nov. de 2014
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 comentarios
Respuesta aceptada
Roger Stafford
el 18 de Nov. de 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.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!