Azzera filtri
Azzera filtri

How to solve this problem?

2 visualizzazioni (ultimi 30 giorni)
Arpita
Arpita il 6 Mar 2024
Commentato: Voss il 7 Mar 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

Risposte (1)

Voss
Voss il 6 Mar 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 Commenti
Arpita
Arpita il 7 Mar 2024
thank you that was very helpful
Voss
Voss il 7 Mar 2024
You're welcome! Any questions, let me know. Otherwise, please "Accept" this answer. Thanks!

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by