Borrar filtros
Borrar filtros

How to solve this problem?

1 visualización (últimos 30 días)
Arpita
Arpita el 6 de Mzo. de 2024
Comentada: Voss el 7 de Mzo. de 2024
Suppose I have an array that is a large m x n matrix. For a value y, if the numbers in this matrix are less than y, then i want to replace those values with 0, otherwise they are 1. how to compute this? I have written a rudimentary code, but i need help.
df = xlsread("Book1.xlsx");
for i = 1:448 %448 = number of columns
x = df(:,i)
if x < 40
x = 0
else
x = 1
i = i + 1
end
end

Respuestas (1)

Voss
Voss el 6 de Mzo. de 2024
y = 0.3;
df = rand(3,4) % random matrix
df = 3×4
0.0521 0.9094 0.8965 0.7698 0.1742 0.3911 0.7067 0.1376 0.8626 0.0311 0.2910 0.0843
df = double(df >= y)
df = 3×4
0 1 1 1 0 1 1 0 1 0 0 0
  3 comentarios
Arpita
Arpita el 7 de Mzo. de 2024
thank you that was very helpful
Voss
Voss el 7 de Mzo. de 2024
You're welcome! Any questions, let me know. Otherwise, please "Accept" this answer. Thanks!

Iniciar sesión para comentar.

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