필터 지우기
필터 지우기

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
  댓글 수: 3
Arpita
Arpita 2024년 3월 7일
thank you that was very helpful
Voss
Voss 2024년 3월 7일
You're welcome! Any questions, let me know. Otherwise, please "Accept" this answer. Thanks!

댓글을 달려면 로그인하십시오.

카테고리

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