how to access individual elements from a variable?

1 回表示 (過去 30 日間)
prateek nahar
prateek nahar 2017 年 11 月 21 日
編集済み: Stephen23 2017 年 11 月 21 日
This is my code s1=[216 46; 176 127; 227 131; 256 170; 176 187];
a=s1(:,1);
disp(a);
b=s1(:,2);
disp(b);
when i execute this i get 216 176 227 256 176 in a and 46 127 131 170 187 in b.
now i want to access individual values from a and b like i want to print only 2nd value of a and 2nd value of b. How to do it.

採用された回答

Stephen23
Stephen23 2017 年 11 月 21 日
編集済み: Stephen23 2017 年 11 月 21 日
If you want the second element of a, then use indexing to get the second element of a:
>> a(2)
ans = 176
Or simply from the original array:
>> s1(2,1)
ans = 176
Basic MATLAB concepts (such as how to use subscript indexing) is covered in the introductory tutorials, which are highly recommended for all beginners:

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by