Compare rows of a column vector

3 visualizaciones (últimos 30 días)
marie lasz
marie lasz el 16 de Feb. de 2021
Respondida: Rik el 17 de Feb. de 2021
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 comentarios
marie lasz
marie lasz el 16 de Feb. de 2021
Editada: marie lasz el 16 de Feb. de 2021
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.
Jan
Jan el 16 de Feb. de 2021
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?

Iniciar sesión para comentar.

Respuestas (2)

Jan
Jan el 16 de Feb. de 2021
Editada: Jan el 16 de Feb. de 2021
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 comentarios
Jan
Jan el 17 de Feb. de 2021
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 el 17 de Feb. de 2021
yes I meant that [0, 0.4, 0.4]. but don't know how it will read row wise.

Iniciar sesión para comentar.


Rik
Rik el 17 de Feb. de 2021
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

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by