필터 지우기
필터 지우기

Vector operations not working correctly

조회 수: 1 (최근 30일)
atan
atan 2019년 6월 16일
댓글: Andrei Bobrov 2019년 6월 16일
I have the following code
cvPredictions = (pval < epsilon)== 1; % Anomaly
cvPredictions = (pval > epsilon)== 0; % Not an anomaly
In the above code, pval is a vector, epsilon is a scalar and cvPredictions will be vector and each element of a vector will be 0 or 1
I want the follwoing
a) if any element of pval is less than epsilon, then, I want the corresponding element of cvPredictions to be 1
b) if any element of pval is greater than epsilon, then, I want the corresponding element of cvPredictions to be 0
I do not want to give a for loop. I do not think the above code is correct. Can anyone suggest me how to achieve a and b in simple one or 2 liner vectorized approach?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 6월 16일
cvPredictions = pval < epsilon;
  댓글 수: 2
atan
atan 2019년 6월 16일
편집: atan 2019년 6월 16일
I do not get it. How can this work?
Andrei Bobrov
Andrei Bobrov 2019년 6월 16일
>> pval = randi(100,6,1)
pval =
82
91
13
92
64
10
>> epsilon = 50
epsilon =
50
>> cvPredictions = pval < epsilon
cvPredictions =
6×1 logical array
0
0
1
0
0
1
>>

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

추가 답변 (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