フィルターのクリア

How to Cell indexing

6 ビュー (過去 30 日間)
dmfwlansejr
dmfwlansejr 2021 年 9 月 13 日
コメント済み: dmfwlansejr 2021 年 9 月 13 日
X1=11;
X2=22;
u{1}=[X1,X2];
>> u{1}
ans =
11 22
How to index 'one' element(ex: '11' or '22')
  1 件のコメント
Stephen23
Stephen23 2021 年 9 月 13 日
@dmfwlansejr: Do you have a reason for storing a numeric vector inside a scalar cell array?

サインインしてコメントする。

採用された回答

Esen Ozbay
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 件のコメント
dmfwlansejr
dmfwlansejr 2021 年 9 月 13 日
Thanks!

サインインしてコメントする。

その他の回答 (1 件)

Chunru
Chunru 2021 年 9 月 13 日
X1=11;
X2=22;
u{1}=[X1,X2];
u{1}
ans = 1×2
11 22
% To access "one" element
u{1}(1)
ans = 11
u{1}(2)
ans = 22

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by