필터 지우기
필터 지우기

How to replace first and last element of each matrix in 7x1 cell with 0

조회 수: 1 (최근 30일)
Tomaszzz
Tomaszzz 2022년 7월 18일
댓글: Tomaszzz 2022년 7월 18일
Hi all,
I have a 7x 1 cell of 101x1 double.
I want to replace first and last element of each matrix with 0. Can you help please?
My approach:
for i = 1:length(cell)
cell{i}((cell(1:1)))=0;
cell{i}((cell(101:101)))=0;
end
Unable to use a value of type cell as an index.

채택된 답변

KSSV
KSSV 2022년 7월 18일
편집: KSSV 2022년 7월 18일
for i = 1:length(cell)
cell{i}(1)=0;
cell{i}(end)=0;
end

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 7월 18일
NewCell = cellfun(@(C) [0; C(2:end-1); 0], OldCell, 'uniform', 0);
Note: using cell as the name of a variable interfers with calling cell() to create a cell array... and confuses people reading your code.

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by