Plotting array filtered by column?

3 visualizaciones (últimos 30 días)
Brandon
Brandon el 19 de Jul. de 2023
Comentada: Jon el 2 de Ag. de 2023
How would I go about graphing columns filtered by specific results in a third column?
The following table as an example, how would I plot only the second and third column entries that are 1.0000 in the first?
A =
1.0000 1.0000 5.5000
1.0000 2.0000 1.2000
0 3.0000 6.4000
1.0000 4.0000 3.7000
0 5.0000 3.6000
0 6.0000 9.6000
  1 comentario
Dyuman Joshi
Dyuman Joshi el 19 de Jul. de 2023
Editada: Dyuman Joshi el 19 de Jul. de 2023
Try comparing with the first column values with 1.000, ideally with a tolerance, and use logical indexing to get the corresponding values in 2nd and 3rd column.

Iniciar sesión para comentar.

Respuesta aceptada

Jon
Jon el 19 de Jul. de 2023
So to make @Dyuman Joshi suggestion more concrete
% Define example points
A = [
1.0000 1.0000 5.5000
1.0000 2.0000 1.2000
0 3.0000 6.4000
1.0000 4.0000 3.7000
0 5.0000 3.6000
0 6.0000 9.6000];
% Define tolerance for finding rows to plot
tol = 1e-6;
% plot rows meeting critiera that element in first column is a 1
idl = ismembertol(A(:,1),1,tol); % or alternatively idl = abs(A(:,1)-1)<=tol
plot(A(idl,2),A(idl,3))
  8 comentarios
Dyuman Joshi
Dyuman Joshi el 2 de Ag. de 2023
You can also use ismember for that.
Jon
Jon el 2 de Ag. de 2023
Yes, that's cleaner and connects back to the beginning of the the thread where the match was approximate and we had to use ismembertol.
% Define example points
A = [
4 1.0000 5.5000
1 2.0000 1.2000
2 3.0000 6.4000
3 4.0000 3.7000
0 5.0000 3.6000
2 6.0000 9.6000];
% Plot rows meeting critiera that element in first column is a 1 or a 2
idl = ismember(A(:,1),[1,2])
idl = 6×1 logical array
0 1 1 0 0 1
plot(A(idl,2),A(idl,3),'o-')

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by