select rows satisfying a particular condition
Mostra commenti meno recenti

having a matrix of dim 5 x 10
if i give start_index = 1, and end_index = 3, i wanted to get rows starting with value of start_index and ending with end_index excluding zeros.
eg: rows 4 and 5
cell_matrix = {[1 2 3]
[1 3] }
saved to a cell matrix
Risposta accettata
Più risposte (1)
Alex Mcaulley
il 25 Apr 2019
Modificato: Alex Mcaulley
il 25 Apr 2019
a = randi([0,2],5,10);
start_index = 1;
end_index = 3;
b = mat2cell(a(start_index:end_index,:),ones(1,end_index-start_index+1),size(a,2));
b = cellfun(@(x) myfun(x),b,'UniformOutput',false);
function x = myfun(x)
x(x==0) = [];
end
Categorie
Scopri di più su MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!