Storing Data from an IF loop
Afficher commentaires plus anciens
Hi all
so i run a foor loop to get the number of pixels in a sample of images, I then want to find the the jumps that are larger 400 pixels, and the store the x value where this occurs, any idea?
thank you in advance :)
x=0;
for x=1:1:56;
x=x+1;
jump(x)=whitepixels9(x)-whitepixels9(x-1);
if -400>jump>400 ;
end
end
Réponses (3)
There is no such thing as an 'if loop'. There are while loops and for loops but an 'if' statement is a conditional.
If whitepixels9() can operate on vectors, you do not need to (and should not) use a for-loop.
If you must use a for loop, here are some comments to consider:
% x=0; % Remove. Unnecessary.
jump = nan(1,56);
for x=1:1:56;
%x=x+1; % Remove. The for-loop does this automatically
% The line below assumes that the output is a scalar
jump(x)=whitepixels9(x)-whitepixels9(x-1);
% if -400>jump>400 ; % Remove.
%
% end
end
keepX = find(jump > 400);
2 commentaires
Lizzy tatarek
le 3 Mai 2019
Adam Danz
le 3 Mai 2019
I just edited my answer. Try that.
KALYAN ACHARJYA
le 3 Mai 2019
image1=rgb2gray(imread('test.jpg')); % image1 gray image
[rows colm]=size(image1);
fprintf('The number of pixel in the image= %d ',rows*colm);
result1=sort(image1(:,:),'descend');
max_pixels=result1(1:400);
% Next find the indexes wheere max_pixels any elements equal in image 1
Lizzy tatarek
le 3 Mai 2019
Catégories
En savoir plus sur Loops and Conditional Statements 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!