필터 지우기
필터 지우기

Change condition 'A=253' into 'A(A=253)=0' with multiple values (for example: A=70 and A=253)

조회 수: 2 (최근 30일)
Hi. I have this code:
value_GS = importdata("value_GS.mat");
value_GS(value_GS=253) = 0;
I want to change the last line of the code so that it can select the numbers 70 and 253.
For example:
value_GS(value_GS=70 && value_GS=253) = 0;

채택된 답변

John D'Errico
John D'Errico 2023년 7월 19일
편집: John D'Errico 2023년 7월 19일
You CAN use an and operator in there. That is fine if you have 2 or maybe even 3 cases. But one day when you have 27 possibilities to test for, you DON"T WANT TO TEST THEM ALL INDIVIDUALLY.
Instead, learn to use ismember. It tests to see which elements lie in a given set.
value_GS(ismember(value_GS,[70, 253])) = 0;

추가 답변 (1개)

Cris LaPierre
Cris LaPierre 2023년 7월 19일
Use the or condition instead of the and. Also, use == to check for equality.
The pseudocode would be "If the value of value_GS is 70 or 253, change the value to 0".
load value_GS
value_GS
value_GS = 6×1
70 254 70 70 255 253
value_GS(value_GS==70 | value_GS==253) = 0
value_GS = 6×1
0 254 0 0 255 0

카테고리

Help CenterFile Exchange에서 Hypothesis Tests에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by