필터 지우기
필터 지우기

How to get a content of a cell array?

조회 수: 83 (최근 30일)
Lara Lirnow
Lara Lirnow 2017년 2월 15일
댓글: emjey 2020년 2월 18일
I have 1x25 cell array, which looks like this :
0.300000 0.410000 ,0.41000 0.430000 ,...
I want to get only first element from the first cell ( 0.300000 ) and put in a variable x, and second element from the first cell (0.410000) and put it into a variable y. How can I do it?

채택된 답변

Guillaume
Guillaume 2017년 2월 15일
"I have 1x25 cell array, which looks like this :"
0.300000 0.410000 ,0.41000 0.430000 ,...
"if I do e.g"
x=C{1,1} %get the first element
"I still get both cell elements '0.300000 0.410000'"
Clearly, one of these statement contradict the other. My suspicion is that your cell array is:
C = {[0.3, 0.41], [0.41, 0.43], ...}
That is, each cell is a 1x2 matrix. To get the 1st element of the matrix in cell 1:
C{1}(1)
%or C{1, 1}(1) if you want to use 2D indexing for the cell array
%or C{1, 1}(1, 1) if you want to use 2D indexing for the matrix as well.
C{1} only gives you the content of the cell, which is a matrix. To access the matrix elements, you use standard () indexing.
  댓글 수: 1
Lara Lirnow
Lara Lirnow 2017년 2월 16일
Thank you so much, this really helped. I actually have cell array where each cell is a 1x2 matrix.

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

추가 답변 (1개)

Easwar Kumar Yarrabikki
Easwar Kumar Yarrabikki 2017년 2월 15일
Hello Lara,
You can do something like
C = { 0.300000 0.410000 ,0.41000 0.430000 }; % your Cell
x=C{1,1} % extracting first element
y=C{1,2} % extracting second element
z=C{1,3} % extracting first element
you can write a simple loop to extract all data at once, if you have very large data.
  댓글 수: 3
Easwar Kumar Yarrabikki
Easwar Kumar Yarrabikki 2017년 2월 15일
Hello Lara.., I tried it once Before I actually Post it, Worked fine. I attached screen shot of my work space below .
emjey
emjey 2020년 2월 18일
How do I extract first two elements, or the second and third at the same time?

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

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by