Extract Previous Cell Value

조회 수: 1 (최근 30일)
Jeffrey Pang
Jeffrey Pang 2019년 4월 21일
댓글: TADA 2019년 4월 23일
I have a cell with char values next to each other as seen below
Cell 1 | Cell 2
____________
'Hello' | 'World'
I would like to define a function that extracts the previous cell value along with the current cell value. I wrote the following code to do so:
t = x{1,i} - Current Cell Value
f = x{2,i-1} - Previous Cell Value, starting with Cell 2 with the previous value of Cell 1
But I keep getting the error
Index in position 2 is invalid. Array indices must be positive integers or logical values.
I believe the error is with regards to the defined function f. It has to do with the i-1 value. At this point, I am stuck. Any thoughts on how to fix that so it works?

답변 (1개)

TADA
TADA 2019년 4월 21일
편집: TADA 2019년 4월 21일
The problem is you're indexing at index 0 which is invalid.
% some specific handling of
% the first cell should be
% executed here if necessary
for i = 2:size(x,2)
t = x{1,i};
f = x{2,i-1};
end
  댓글 수: 6
Jeffrey Pang
Jeffrey Pang 2019년 4월 23일
I got it. Thank you for putting me on the right track!
TADA
TADA 2019년 4월 23일
Cheers
Good luck

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

카테고리

Help CenterFile Exchange에서 Conway's Game of Life에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by