How to replace 0 value with 3 in Matlab

Hello, I hope you are doing well, I am trying to do two thing.
1. Find the number exist in fifth column of data e.g 0,1,2
2. Replace the 0 value in fifth column to 3

回答 (1 件)

KSSV
KSSV 2022 年 12 月 2 日

0 投票

c5 = Dataset(:,5) ;
% Find the number of 0, 1, 2
idx = c5 == 0 | c5 == 1 | c5 == 2 ; % gives logical indices
nnz(idx) % this gives total number
% Replace 0 with 3
c5(c5==0) = 3 ;

2 件のコメント

Med Future
Med Future 2022 年 12 月 2 日
@KSSV the output c5 only shows indexes not all the dataset value for example remaining four columns
Med Future
Med Future 2022 年 12 月 2 日
@KSSV why u use the following command if i have other indexes till 10 how it will work
idx = c5 == 0 | c5 == 1 | c5 == 2 ; % gives logical indices

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

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 12 月 2 日

コメント済み:

2022 年 12 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by