how to remove all the value zero in column 2?

3 ビュー (過去 30 日間)
RACHEL LYN JAHIRIN
RACHEL LYN JAHIRIN 2023 年 11 月 16 日
コメント済み: Dyuman Joshi 2024 年 2 月 25 日
hi, i am new in matlab. can someone help me on how to remove of the zero value in column 2 of database as shown above? can see the coding attach. thankyou so much!

回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2023 年 11 月 16 日
編集済み: Dyuman Joshi 2023 年 11 月 16 日
%Example
A = num2cell([0;rand(10,1);0;0;rand(5,1);0;0;0;1]);
B = num2cell(char(randi([30 50], numel(A), 1)));
C = [B A]
C = 22×2 cell array
{'('} {[ 0]} {'.'} {[0.7471]} {'#'} {[0.2366]} {'"'} {[0.2619]} {'□'} {[0.6682]} {'&'} {[0.3394]} {'"'} {[0.4581]} {'('} {[0.4928]} {'''} {[0.1664]} {'+'} {[0.4145]} {','} {[0.6213]} {'#'} {[ 0]} {'/'} {[ 0]} {'*'} {[0.9919]} {'2'} {[0.4193]} {','} {[0.4106]}
%Find zeros in the 2nd column of the cell array
idx = cellfun(@(x) ~x, C(:,2));
%Remove them
C(idx, 2) = {[]}
C = 22×2 cell array
{'('} {0×0 double} {'.'} {[ 0.7471]} {'#'} {[ 0.2366]} {'"'} {[ 0.2619]} {'□'} {[ 0.6682]} {'&'} {[ 0.3394]} {'"'} {[ 0.4581]} {'('} {[ 0.4928]} {'''} {[ 0.1664]} {'+'} {[ 0.4145]} {','} {[ 0.6213]} {'#'} {0×0 double} {'/'} {0×0 double} {'*'} {[ 0.9919]} {'2'} {[ 0.4193]} {','} {[ 0.4106]}
  3 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 16 日
編集済み: Dyuman Joshi 2023 年 11 月 17 日
"how if i want to remove all the row that has zero value in column 2?"
@RACHEL LYN JAHIRIN, In that case try this -
%Example
A = num2cell([0;rand(10,1);0;0;rand(5,1);0;0;0;1]);
B = num2cell(char(randi([30 50], numel(A), 1)));
C = [B A]
C = 22×2 cell array
{'*'} {[ 0]} {'/'} {[0.9376]} {'&'} {[0.3174]} {','} {[0.2807]} {'$'} {[0.7568]} {')'} {[0.3109]} {'#'} {[0.0463]} {')'} {[0.1515]} {'□'} {[0.2197]} {' '} {[0.6444]} {'0'} {[0.5528]} {'*'} {[ 0]} {'0'} {[ 0]} {'&'} {[0.4588]} {'2'} {[0.9759]} {'$'} {[0.3307]}
%Find zeros in the 2nd column of the cell array
idx = cellfun(@(x) ~x, C(:,2));
%Remove them
C(idx, :) = []
C = 16×2 cell array
{'/'} {[0.9376]} {'&'} {[0.3174]} {','} {[0.2807]} {'$'} {[0.7568]} {')'} {[0.3109]} {'#'} {[0.0463]} {')'} {[0.1515]} {'□'} {[0.2197]} {' '} {[0.6444]} {'0'} {[0.5528]} {'&'} {[0.4588]} {'2'} {[0.9759]} {'$'} {[0.3307]} {'+'} {[0.7091]} {'0'} {[0.4961]} {','} {[ 1]}
Dyuman Joshi
Dyuman Joshi 2024 年 2 月 25 日
Any updates, @RACHEL LYN JAHIRIN?

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

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by