필터 지우기
필터 지우기

Remove elements in cell array based on index of elements

조회 수: 18 (최근 30일)
Jonathan Cheong
Jonathan Cheong 2021년 3월 17일
댓글: Jonathan Cheong 2021년 3월 17일
Hello, I would like to remove elements in a cell array based on index number from another cell array.
For example:
A = [1, 15, 25, 30] B = [1, 4]
A is the data cell array, B is the cell array with indices of elements I want to remove
Output:
A = [15, 25]
for ki = 1:length(difcell)
condition1 = cellfun(@(x)(x<0),difcell,'UniformOutput',false);
gk = cellfun(@(x) find(x==1),condition1,'UniformOutput', false);
% I'm stuck at this stage
% smcell = cellfun(@(x) x(gk), smcell, 'Uniform', 0);
end
Many thanks in advance.
  댓글 수: 1
Jonathan Cheong
Jonathan Cheong 2021년 3월 17일
Just to clarify!
'gk' is the index cell array
'smcell' is the data cell array

댓글을 달려면 로그인하십시오.

채택된 답변

Jonathan Cheong
Jonathan Cheong 2021년 3월 17일
for ki = 1:length(difceller)
condition1 = cellfun(@(x)(x<0),difceller,'UniformOutput',false);
smcellere = cellfun(@(x,y) ~y(x==1),condition1,smceller,'Uniform',0);
errorcellere = cellfun(@(x,y) ~y(x==1),condition1,errorceller,'Uniform',0);
end

추가 답변 (1개)

Jonathan Cheong
Jonathan Cheong 2021년 3월 17일
for ki = 1:length(difcell)
condition1 = cellfun(@(x)(x<0),difcell,'UniformOutput',false);
gk = cellfun(@(x,y) y(x==1),condition1,smcell,'Uniform',0);
end
smcellclean = cellfun(@(x,y) x(~ismember(x,y)), smcell, gk,'Uniform',0);
Instead of using index I find values that are the same and removed them.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by