Fill empty matrix with determined values
Afficher commentaires plus anciens
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 commentaire
James Knowles
le 15 Déc 2017
Réponse acceptée
Plus de réponses (1)
Jos (10584)
le 15 Déc 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?
Catégories
En savoir plus sur Common Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!