How to solve this problem?

2 次查看(过去 30 天)
Arpita
Arpita 2024-3-6
评论: Voss 2024-3-7
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

回答(1 个)

Voss
Voss 2024-3-6
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

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by