How to Cell indexing
조회 수: 6 (최근 30일)
이전 댓글 표시
X1=11;
X2=22;
u{1}=[X1,X2];
>> u{1}
ans =
11 22
How to index 'one' element(ex: '11' or '22')
댓글 수: 1
Stephen23
2021년 9월 13일
@dmfwlansejr: Do you have a reason for storing a numeric vector inside a scalar cell array?
채택된 답변
Esen Ozbay
2021년 9월 13일
편집: Esen Ozbay
2021년 9월 13일
If you want, you can access X1 as
X1=11;
X2=22;
u{1}=[X1,X2];
u{1}(1) % this will yield ans = 11;
The above notation means:
Access the first element of the cell array u, which is [11 22]. Then, access the first element of the first element, which is 11.
However, if you want to keep X1 and X2 in separate elements of the cell array,
u{1} = X1;
u{2} = X2;
u{1} % this will yield ans = 11;
u{2} % this will yield ans = 22;
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Exploration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!