Borrar filtros
Borrar filtros

How to check value in matrix from 2 specific column

3 visualizaciones (últimos 30 días)
Chau Chin Haw
Chau Chin Haw el 21 de Dic. de 2020
Respondida: Image Analyst el 21 de Dic. de 2020
I have a data of
linedata = [1 1 2 2
2 2 3 1.5
3 3 4 2.2
4 4 5 6.8
5 4 6 1
6 5 7 5.1
7 6 8 2.5
8 7 9 3.3
9 8 10 2.8
10 8 11 1.4
11 10 12 3.2
12 11 13 2.7
13 12 14 1.9
14 13 15 4.5];
I would like to ask how can i check for value 7 and 8 in column 2 and column 3. I am using find function to find the value but it cant seems to work. Can anyone help? Thanks in advance.
  2 comentarios
the cyclist
the cyclist el 21 de Dic. de 2020
It is unclear to me exactly what you want. Do you want to check the two columns separately? Or are you trying to check the condition in both columns?
For example, are you trying to check if column 2 is equal to 7, while column 3 is equal to 8?
Do you need the indices, or is logical output ok?
Can you tell us what exactly you expect the output to be for this input? (Better to express it in MATLAB syntax, not English words.)
Chau Chin Haw
Chau Chin Haw el 21 de Dic. de 2020
sorry there are some mistake in my question.
linedata = [1 1 2 2
2 2 3 1.5
3 3 4 2.2
4 4 5 6.8
5 4 6 1
6 5 7 5.1
7 6 8 2.5
8 7 9 3.3
9 8 10 2.8
10 8 11 1.4
11 10 12 3.2
12 11 13 2.7
13 12 14 1.9
14 13 15 4.5];
% Check value 7 and value 8 in column 2
tried using find function
row_check(i)=find(linedata(:,2)==col2(i))
but error occur
Unable to perform assignment because the left and right sides have a different number of elements

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 21 de Dic. de 2020
Explain exactly what "check for" means. Until then, try
% See if row 7 and 8, both in column 2, match
if linedata(7, 2) == linedata(8, 2)
fprintf(['linedata(7, 2) equals linedata(8, 2)\n');
else
fprintf(['linedata(7, 2) does not equal linedata(8, 2)\n');
end
% See if row 7 and 8, both in column 2, match
if linedata(7, 3) == linedata(8, 3)
fprintf(['linedata(7, 3) equals linedata(8, 3)\n');
else
fprintf(['linedata(7, 3) does not equal linedata(8, 3)\n');
end

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by