Storing Data from an IF loop
6 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (3 件)
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 件のコメント
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!