How to save variables into a matrix

25 vues (au cours des 30 derniers jours)
Oscar Zampi
Oscar Zampi le 14 Fév 2021
Commenté : Oscar Zampi le 14 Fév 2021
Hi, I have the following code that produces i, j and z values. Is it possible to save the values in a matrix instead of just displaying them using fprintf?
Thanks
sz = size(ortho);
md= median(ortho);
pks = zeros(sz(1),sz(2));
for i =2:sz(1)-1
for j =2:sz(2)-1
if ortho(i-1,j) < ortho(i,j) & ...
ortho(i+1,j-1) < ortho(i,j) & ...
ortho(i,j-1) < ortho(i,j) & ...
ortho(i,j+1) < ortho(i,j)
pks(i,j) = 1;
fprintf("i=%d j=%d z=%d \n",i,j,ortho(i,j));
end
end
end

Réponse acceptée

KSSV
KSSV le 14 Fév 2021
count = 0 ;
iwant = zeros([],3) ; % to store i,j,ortho(i,j) in respective columns
sz = size(ortho);
md= median(ortho);
pks = zeros(sz(1),sz(2));
for i =2:sz(1)-1
for j =2:sz(2)-1
if ortho(i-1,j) < ortho(i,j) & ...
ortho(i+1,j-1) < ortho(i,j) & ...
ortho(i,j-1) < ortho(i,j) & ...
ortho(i,j+1) < ortho(i,j)
pks(i,j) = 1;
fprintf("i=%d j=%d z=%d \n",i,j,ortho(i,j));
count = count+1 ;
iwant(count,:) = [i j ortho(i,j)] ;
end
end
end
iwant
  1 commentaire
Oscar Zampi
Oscar Zampi le 14 Fév 2021
Thank you very much, it works perfectly.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Mobile Fundamentals dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by