Fill empty matrix with determined values
이전 댓글 표시
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개)
Jos (10584)
2017년 12월 15일
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?
카테고리
도움말 센터 및 File Exchange에서 Common Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!