Storing Data from an IF loop

6 ビュー (過去 30 日間)
Lizzy tatarek
Lizzy tatarek 2019 年 5 月 3 日
回答済み: Lizzy tatarek 2019 年 5 月 3 日
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

回答 (3 件)

Adam Danz
Adam Danz 2019 年 5 月 3 日
編集済み: Adam Danz 2019 年 5 月 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 件のコメント
Lizzy tatarek
Lizzy tatarek 2019 年 5 月 3 日
I do this but it shows no jumps larger than 400 even though there definitely are?
Adam Danz
Adam Danz 2019 年 5 月 3 日
I just edited my answer. Try that.

サインインしてコメントする。


KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 5 月 3 日
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
Lizzy tatarek 2019 年 5 月 3 日
for x=2:1:56
jump(x)=whitepixels9(x)-whitepixels9(x-1);
if jump(x)>400
jump(x)=whitepixels9(x);
else
jump(x)=0;
end
end
I ended up doing this which is fit for my use and made it possible to plot it on a graph of the pixel number in each image

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by