필터 지우기
필터 지우기

How to use parfor to delete the first c elements of each cell of b?

조회 수: 2 (최근 30일)
Chaoyang Jiang
Chaoyang Jiang 2018년 5월 15일
댓글: Image Analyst 2018년 5월 15일
How to use parfor to delete the first c elements of cell b?
Error: The variable b in a parfor cannot be classified.
b=cell(1000,1);
c=randi(2,1000,1);
parfor m=1:1000
b{m,1}(1:c(m))=[];
end

답변 (1개)

Image Analyst
Image Analyst 2018년 5월 15일
Try this:
b=cell(1000,1); % Initialize to empty cells.
c = 10; % Whatever.
% Delete the first c cells
b(1:c) = [];
% Check that we have 9990 cells now.
whos b
  댓글 수: 2
Chaoyang Jiang
Chaoyang Jiang 2018년 5월 15일
Thank you for your answer. I want to delete the first c elements of each cell of b. E.g,
b{1,1}=[1 3 4];
c(1)=2;
b{1,1}c(1)=[];
then b{1,1}={4}
Image Analyst
Image Analyst 2018년 5월 15일
Try this then:
% Create some random b
b = cell(10, 1);
for k = 1 : length(b)
b{k} = randi(99, 1, 5);
end
celldisp(b);
% Define c - it's random for each cell of b.
c = randi(4, length(b), 1)
% Use each c to delete that many elements from
% the corresponding cell of b
for k = 1 : length(b)
thisCell = b{k};
b{k} = thisCell(c(k)+1:end);
end
celldisp(b);
% or use cellfun().

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by