필터 지우기
필터 지우기

How to perform single cell array pairwise difference?

조회 수: 1 (최근 30일)
Syed Haider
Syed Haider 2014년 11월 1일
댓글: Syed Haider 2014년 11월 1일
Hello everyone! I am working on cell array of size X x Y where X and Y will be variable and depends on the size of input image. Lets consider a case where X = 16 and Y = 16. I have one cell array variable and in each cell i have 1001 rows with first column simulation time and second column data. What i want is the following: I have to perform difference of two consecutive cells and store result in new cell. This new cell should have a sequence of differences.
Example:
New_Cell_Array{1,1} = Old_Cell_Array{1,1} - Old_Cell_Array{2,1};
New_Cell_Array{2,1} = Old_Cell_Array{3,1} - Old_Cell_Array{4,1};
and so on..
New_Cell_Array{X/2,1} = Old_Cell_Array{X-1,1} - Old_Cell_Array{X,1};
New_Cell_Array{X/2+1,1} = Old_Cell_Array{2,1} - Old_Cell_Array{3,1};
New_Cell_Array{X/2+2,1} = Old_Cell_Array{4,1} - Old_Cell_Array{5,1};
and so on..
New_Cell_Array{X-1,1} = Old_Cell_Array{14,1} - Old_Cell_Array{15,1};
Is there any way to perform this kind of operation on cell array. Thanks in advance.
  댓글 수: 3
Guillaume
Guillaume 2014년 11월 1일
You wrote ' Lets consider a case where X = 16 and Y = 16', yet your example only shows what happens in the first column. What happens in the other columns? The same?
Syed Haider
Syed Haider 2014년 11월 1일
Actually i am confused with how to first perform difference of first and second row, then third and fourth row, and so on.. once all are done, then i will start with difference of second row with third row, fourth row with fifth row and so on.

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

채택된 답변

Guillaume
Guillaume 2014년 11월 1일
As per isakson's comment, it's fairly straightforward to do with a for loop.
You could also do it with cellfun, but be aware that due to the anonymous function call, it may not be faster than the explicit loop:
new_cell_array = cellfun(@(c1, c2) c1-c2, old_cell_array(1:2:end, :), old_cell_array(2:2:end, :), 'UniformOutput', false);
  댓글 수: 1
Syed Haider
Syed Haider 2014년 11월 1일
yeah it worked , similarly i should use the same for the other part as : new_cell_array = cellfun(@(c1, c2) c1-c2, old_cell_array(2:2:end, :), old_cell_array(3:2:end, :), 'UniformOutput', false);
Thanks alot brother. you saved my time.

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

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by