Fill empty matrix with determined values
Mostrar comentarios más antiguos
I am trying to enter the first local maxima of 'matrix1' into 'empty_matrix' over a certain range. There are three possible outcomes of local maxima, nothing (0), a 1X1 matrix and a 2X1 matrix. The issue is 'empty_matrix' wont fill up as desired
matrix1 = rand(50,50,500);
matrix2 = rand(50,1);
empty_matrix = zeros(50,50);
for nx=1:50
for ny=1:50
desired_range = squeeze(matrix1(nx,ny,1:50));
[pks, loc] = findpeaks(desired_range(:));
if pks == 0
empty_matrix(ny,nx) = NaN;
elseif pks == size(zeros(2,1))
empty_matrix(ny,nx) = matrix2(loc(1)); %want the first local maximum
elseif pks == size([])
empty_matrix(ny,nx) = matrix2(loc);
end
end
end
1 comentario
James Knowles
el 15 de Dic. de 2017
Respuesta aceptada
Más respuestas (1)
Jos (10584)
el 15 de Dic. de 2017
To check is a variable is empty use the function isempty.
a = []
isempty(a)
You might also want to check you if-elseif-else-end loop. The else is missing :) Are you sure about that?
Categorías
Más información sobre Common Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!