Compare rows of a column vector

Hey beautiful people,
I am confused here that i have this vector and i have to compare three values of each row and result should give the most appearing (frequent )value. It is a kind or error correction , in some rows there is one different value and two values are same which I didn't capture. Can some one help me how should i compare each row with three col values? that is how I obtained that by this code.
vec= ones(1024, 1);
ex=[1 1 1];
ex_vec=vec.*ex;
b_w_img--watermarked image
b_img--host image
for k = 1 : numel(b_img)
% diff = b_W_img{k}(4,2) - b_img{k}(4,2);
diff = round((b_W_img{k}(4,2)),1) -round(( b_img{k}(4,2)),1);
ex_vec(k)=diff;
end

댓글 수: 5

KSSV
KSSV 2021년 2월 16일
Read about unique, ismember.
marie lasz
marie lasz 2021년 2월 16일
thanks and how it will read every row , i know i have to make a loop but don't know how to define rows?
Rik
Rik 2021년 2월 16일
You might not need a loop. Did you read the documentation for those two functions?
marie lasz
marie lasz 2021년 2월 16일
편집: marie lasz 2021년 2월 16일
Not yet , because I was testing with mode function. and why I will not need a loop ? I have to insert those single value resulty in a matrix. Let me see the documentation.
Do you mean:
ex_vec(k, :) = diff;
% ^
The code
vec= ones(1024, 1);
ex=[1 1 1];
ex_vec=vec.*ex;
can be simplified to:
ex_vec = zeros(1024, 3);
Or do I oversee something?

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2021년 2월 16일
편집: Jan 2021년 2월 16일

0 개 추천

The screenshot show the contents of ex_vec. It does not matter how you have obtained it. All you want to know is how to find rows with less then 3 equal elements. Did I understand this correctly?
not3EqElem = sum(ex_vec == min(ex_vec, [], 1)) < 3;
or
not3EqElem = ~(ex_vec(:, 1) == ex_vec(:, 2) & ex_vec(:, 2) == ex_vec(:, 3));

댓글 수: 7

marie lasz
marie lasz 2021년 2월 16일
no not like that, every row contains 3 elements and i have to extract the value which appears more than 1 time and then store in the matrix. There are 1024 columns with 3 rows.
marie lasz
marie lasz 2021년 2월 16일
I mean like if a row has[ 0, 0,4 -0,4 ]values, then it means that I 0,4 is the most frequently appearing value and i need that result. If you know about error correction , in which sometimes one bit is flipped or one bit gives wrong value, so I am doing kind of that thing.
Walter Roberson
Walter Roberson 2021년 2월 16일
That appear more than one time, considering each row individually? What do you want to do if the entries in a given row are unique?
marie lasz
marie lasz 2021년 2월 16일
yes i want to consider/compare each row individually and then will apply the condition that if it is 0,4 then the bit will be zero else will be 1 .
marie lasz
marie lasz 2021년 2월 16일
like the concept of mode in which we take value which has more frequency /repetition. a=1 1 2;
mode=1
Jan
Jan 2021년 2월 17일
Why is 0.4 the most frequent value in [ 0, 0,4 -0,4 ] ? Do you mean [0, 0.4, 0.4] or should the sign be ignored?
If mode() satisfies your needs, using this command would be athe best idea.
marie lasz
marie lasz 2021년 2월 17일
yes I meant that [0, 0.4, 0.4]. but don't know how it will read row wise.

댓글을 달려면 로그인하십시오.

Rik
Rik 2021년 2월 17일

0 개 추천

Just like most functions like it, mode allows you to specify the dimension to operate on:
A= [0, 0.4, 0.4;...
1, 1, 0];
mode(A,2)
ans = 2×1
0.4000 1.0000

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

질문:

2021년 2월 16일

답변:

Rik
2021년 2월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by