How to use logical expressions to change the values of a column who matches a condition on a different column?

1 回表示 (過去 30 日間)
If we have a matrix M like
V1. V2. V3.
1 1 1
2 4 9
3 4 0
4 4 3
5 5 1
6 9 5
7 0 3
8 4 5
9 4 6
10 5 2
How could we make zero the values of V2 and V3 which are from 4 to 7? obtaining M2 like:
V1. V2. V3.
1 1 1
2 4 9
3 4 0
4 0 0
5 0 0
6 0 0
7 0 0
8 4 5
9 4 6
10 5 2

採用された回答

Birdman
Birdman 2018 年 2 月 13 日
編集済み: Birdman 2018 年 2 月 13 日
M=[1 1 1
2 4 9
3 4 0
4 4 3
5 5 1
6 9 5
7 0 3
8 4 5
9 4 6
10 5 2];
M(4:7,2:3)=0
  1 件のコメント
Philippe Corner
Philippe Corner 2018 年 3 月 23 日
Mr. Bird man, could you check this problem please? https://la.mathworks.com/matlabcentral/answers/390255-how-to-modify-the-code-changing-the-intervals

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2018 年 2 月 13 日
>> V = [1 1
4 9
4 0
4 3
5 1
9 5
0 3
4 5
4 6
5 2];
>> V(4:7,:)=0
V =
1 1
4 9
4 0
0 0
0 0
0 0
0 0
4 5
4 6
5 2
>>
  1 件のコメント
Philippe Corner
Philippe Corner 2018 年 3 月 23 日
Mr. Andrei, could you check this problem please? https://la.mathworks.com/matlabcentral/answers/390255-how-to-modify-the-code-changing-the-intervals

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by