필터 지우기
필터 지우기

subtraction on the cells elements

조회 수: 3 (최근 30일)
johnson saldanha
johnson saldanha 2018년 12월 11일
댓글: Guillaume 2018년 12월 11일
i have a cell array x of size 12*1
and the cells are column vectors of type double
x{1,1}=[1 2 5 6 7 7 8 ];
x{2,1}=[ 1 2 6 6 7 8 8]
and so on
i want the output y as a cell array with
y{1,1}=[1 1 3 1 1 0 1];
y{2,1}=[1 1 4 0 1 1 0];
the elements of the cell in the output should be the difference i-(i-1). let the first element be as it is it. start with i =2:length x{i,1}
for each each cell the operation shouldbe done and stored in a different cell
  댓글 수: 1
johnson saldanha
johnson saldanha 2018년 12월 11일
편집: Guillaume 2018년 12월 11일
acc={}
for i=1:size(out,1)
y=out{i,1};
for i=2:length(y)
acc(i)=y(i)-y(i-1);
end
acc{i,1}=num2cell(acc);
end
Conversion to cell from double is not possible.
Error in accelerationrate (line 66)
acc(i)=y(i)-y(i-1);
i tried this and im getting this error.

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

채택된 답변

Guillaume
Guillaume 2018년 12월 11일
Note that [1 2 5 6 7 7 8 ] in your example is a row vector, not a column vector as you state. If the content of the cells are indeed column vectors then you'll have to change the , into ; where indicated
%demo data
x = num2cell(randi(10, 12, 10), 2)
%processing
y = cellfun(@(vec) [vec(1), diff(vec)], x, 'UniformOutput', false) %replace [vec(1), by [vec(1); if working on column vectors
or if you want to use a loop instead of cellfun:
y = cell(size(x)); %preallocation
for idx = 1:numel(x)
y{idx} = [x{idx}(1), diff(x{dix})]; %replace , by ; for column vectors
end
  댓글 수: 2
johnson saldanha
johnson saldanha 2018년 12월 11일
ifi have to make the first row in every cell element as 0 how do i do it
Guillaume
Guillaume 2018년 12월 11일
Replace vec(1) or x{idx}(1) by 0.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by