Worki ng with cells

조회 수: 1 (최근 30일)
soloby
soloby 2015년 6월 26일
댓글: Walter Roberson 2015년 6월 26일
hey all,
i have a cell of <1x20> dimensions and each cell contains two x-values in a coordinate.
I want to work with these two coordinates separately, but I dont know how to access them?
Xidx1 =
Columns 1 through 5
[1x2 double] [1x2 double] [1x2 double] [1x2 double] [1x2 double]
Columns 6 through 10
[1x2 double] [1x2 double] [1x2 double] [1x2 double] [1x2 double]
Columns 11 through 15
[1x2 double] [1x2 double] [1x2 double] [1x2 double] [1x2 double]
Columns 16 through 20
[1x2 double] [1x2 double] [1x2 double] [1x2 double] [0]
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 6월 26일
Xidx1{20} is only [0] not a pair of values.

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

채택된 답변

Jan
Jan 2015년 6월 26일
편집: Jan 2015년 6월 26일
Get the 2nd coordinate of the 3rd pair:
element = Xidx1{3}(2)
The power of a cell array is to store elements of different size and/or type. In your case only the last element contains a deviating contents. Is the [0] useful for anything? If not, you can concatenate the vectors to a matrix:
index = cat(1, Xidx1{1:end-1});
element = index(3, 2);

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 26일
cellfun(@(v) v(1), Xidx1)
  댓글 수: 2
soloby
soloby 2015년 6월 26일
This is great! thanks.
It seems like it's giving me the first value of each pair, what do i do to get the second value?
Walter Roberson
Walter Roberson 2015년 6월 26일
Obviously
cellfun(@(v) v(2), Xidx1)

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

카테고리

Help CenterFile Exchange에서 Other Formats에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by