フィルターのクリア

Logical operations on matrix

4 ビュー (過去 30 日間)
Brattv
Brattv 2016 年 2 月 4 日
コメント済み: Image Analyst 2016 年 2 月 4 日
Hello,
I thought i had this figured but i am having trouble with logical operations on a matrix. The code is:
% Quantization stepsize
hQ = 12;
% Quantization levels
hQInt = [0:hQ:360];
% Quantization matrix
hueQuant = zeros(600,800);
for i=5:5
hueQuant(hQInt(i)< hue >hQInt(i+1)) = 1;
end
The idea: I am making quantization intervals with hQInt. I want to use a logical operation in the "for-loop", and i thought this statement said - "The index in hue where hue is larger than hQInt(i) and less than hQInt(i+1) is set to 1 in the matrix hueQuant". Just to mention it, the iteration index is set to 5 for test purpose.
The question: Am i wrong or is it possible this way? Any suggestions to how it can be solved without a massive for loop code?
  1 件のコメント
Stephen23
Stephen23 2016 年 2 月 4 日
Vegard B's "Answer" moved here:
Thanks to both of you for the reply! The solution by Kelly Kearney removed the need to loop and was chosen.

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

採用された回答

Kelly Kearney
Kelly Kearney 2016 年 2 月 4 日
編集済み: Kelly Kearney 2016 年 2 月 4 日
Assuming I'm understanding your intent, a better way to do this would be with histc. No loop necessary:
hQ = 12;
hQInt = [0:hQ:360];
hue = rand(600,800)*360;
[~,hueQuant] = histc(hue, hQInt);
  3 件のコメント
Kelly Kearney
Kelly Kearney 2016 年 2 月 4 日
Oh, nice! I hadn't noticed that addition, and both the last-edge treatment and the ability to specify which bin side is the included in the bins are much-needed features for me.
Image Analyst
Image Analyst 2016 年 2 月 4 日
That's probably what is wanted. I never was able to figure out why they wanted to set hueQuant equal to 1 essentially everywhere. Both in code, and verbally they said that. That doesn't make sense to me.

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

その他の回答 (1 件)

Star Strider
Star Strider 2016 年 2 月 4 日
Assuming I understand correctly what you want to do, this statement:
hueQuant(hQInt(i)< hue >hQInt(i+1)) = 1;
would likely do what you want if you restated it as:
hueQuant((hQInt(i)< hue) & (hue >hQInt(i+1))) = 1;
  1 件のコメント
Image Analyst
Image Analyst 2016 年 2 月 4 日
Of course hue would have to be defined first. And it's funny how they talk about a massive for loop when none of the arrays or sizes there, like 5 or 600*800, constitute "massive."

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

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by