フィルターのクリア

Change value for another value

3 ビュー (過去 30 日間)
Sarah Yun
Sarah Yun 2020 年 1 月 18 日
コメント済み: BN 2020 年 1 月 18 日
I have some 99999 values in my array.
I want to change all of them to 0.
Is there code to change all the values at once?
Or do I need to change values in every column of the array?

回答 (3 件)

Star Strider
Star Strider 2020 年 1 月 18 日
編集済み: Star Strider 2020 年 1 月 18 日
Consider this example:
A = [99999 rand(1,2); rand 99999 rand; rand(1,2) 99999];
B = A;
B(A == 99999) = 0
producing:
A = 99999 0.82631 0.9912
0.52395 99999 0.92544
0.73902 0.56743 99999
and:
B =
0 0.82631 0.9912
0.52395 0 0.92544
0.73902 0.56743 0
Make any necessary changes to get the result you want.

stozaki
stozaki 2020 年 1 月 18 日
編集済み: stozaki 2020 年 1 月 18 日
Hello Sarah,
Sample code with a reduced number of arrays.
In your case, it's an array of 99999 values, not an array of 25 values.
>> A=[1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20; 21 22 23 24 25]
A =
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
>> A(:)=0
A =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Please refer colon.
Regards,
stozaki

BN
BN 2020 年 1 月 18 日
編集済み: BN 2020 年 1 月 18 日
Hi, If I understood you well, you need this?
If Array is your Array, then:
index=find(Array==99999); % find all 99999 values. Replace Array with name of your array
Array(index)=0; %change 99999 to 0. Replace Array with name of your array
This code search whole your array to find 99999 numbers, then replacing all of them to 0.
Best Regards
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 1 月 18 日
You do not need the find(), you could use
index = Array===99999;
Array(index) = 0;
BN
BN 2020 年 1 月 18 日
Thank you Walter Roberson.

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by