How to remove indexed set of rows from a cell array

조회 수: 3 (최근 30일)
james sinos
james sinos 2021년 8월 29일
편집: Wan Ji 2021년 8월 29일
i have a cell array "corb " = 10×5 cell array
1- first question :
i want to find the indexes of all elements in the first column , 100000< element <300000
i tried this it doesn't work : row_indices = find(cell2mat(corb(:,1))>100000 & corb(:,1))<300000)
2- Second question :
once i have the vector containing row indexes values lets say its V=[ 3;5;10]
I would like to create a new cell array that has all of the rows from the original cell array EXCEPT for the rows specified by V. ( remove those rows).
so how to proceed

답변 (2개)

the cyclist
the cyclist 2021년 8월 29일
편집: the cyclist 2021년 8월 29일
% Identify rows
row_indices = find(cell2mat(corb(:,1))>100000 & cell2mat(corb(:,1))<300000);
% Define new array that is the same as corb, but and remove rows
corb2 = corb;
corb2(row_indices,:) = [];

Wan Ji
Wan Ji 2021년 8월 29일
편집: Wan Ji 2021년 8월 29일
Try this
logical_indices = arrayfun(@(i)corb{i,1}(1)>100000&corb{i,1}(1)<300000,(1:1:size(corb))');
row_indices = find(logical_indices); % actually this line can be deleted to save time
corb2 = corb(~logical_indices,:); % this is what you want

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by