How to store values in a array from a loop?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi; I have the following code:
Y = imread('img14g.tif');
X = imread('img14bl.tif');
Samples_Y = Y(1:20:512, 1:20:768);
Samples_X = X(1:20:512, 1:20:768);
N = size(Samples_X,1) * size(Samples_X,2); % Number of pixels
Z = zeros(N,7);
for i = 2:25
for j = 2:38
for m = 1:N
Z(m,:)=[Samples_X(i, j), Samples_X(i, j+1),Samples_X(i,j-1), ...
Samples_X(i-1,j+1),Samples_X(i+1,j+1),Samples_X(i-1,j-1),Samples_X(i+1,j-1)];
end
end
end
I need to store the set of pixels in Z but it only stores the last set of pixels for (25,38) on each row of Z. Can somebody help me with this?
0 commentaires
Réponse acceptée
dpb
le 13 Avr 2017
...
m=0;
for i = 2:25
for j = 2:38
m=m+1;
Z(m,:)=[Samples_X(i, j), Samples_X(i, j+1),Samples_X(i,j-1), ...
Samples_X(i-1,j+1),Samples_X(i+1,j+1),Samples_X(i-1,j-1),Samples_X(i+1,j-1)];
end
end
Your loop is storing the same value in all rows every pass thru.
NB: length(2:25)=24 and length(2:38)=37 whereas N=26*39 so your end array is smaller than N by 888 vis a vis 1014 for whatever that matters.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!