how to remove all the value zero in column 2?
Ältere Kommentare anzeigen

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!
Antworten (1)
Dyuman Joshi
am 16 Nov. 2023
Bearbeitet: Dyuman Joshi
am 16 Nov. 2023
%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]
%Find zeros in the 2nd column of the cell array
idx = cellfun(@(x) ~x, C(:,2));
%Remove them
C(idx, 2) = {[]}
3 Kommentare
RACHEL LYN JAHIRIN
am 16 Nov. 2023
Bearbeitet: RACHEL LYN JAHIRIN
am 16 Nov. 2023
Dyuman Joshi
am 16 Nov. 2023
Bearbeitet: Dyuman Joshi
am 17 Nov. 2023
"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]
%Find zeros in the 2nd column of the cell array
idx = cellfun(@(x) ~x, C(:,2));
%Remove them
C(idx, :) = []
Dyuman Joshi
am 25 Feb. 2024
Kategorien
Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!