Save a column as a variable

42 ビュー (過去 30 日間)
Liliana Sierra
Liliana Sierra 2017 年 12 月 13 日
編集済み: Harish Ramachandran 2017 年 12 月 19 日
Hi! This is the code I have so far:
c=zeros(271,4);
for k=150:420;%
c(k-149,1)=k;%i
c(k-149,2)=sum(LENG2*10==k);%
c(k-149,3)=sum(LENG2*10==k)/4.1937
I was wondering if there is a way to store this
c(k-149,3)=sum(LENG2*10==k)/4.1937
as a single variable? Thank you!
Lili.

回答 (1 件)

Harish Ramachandran
Harish Ramachandran 2017 年 12 月 19 日
編集済み: Harish Ramachandran 2017 年 12 月 19 日
Hi Lili,
If I understand correctly, you fill the matrix c with data inside the 'for' loop and now you want to extract/copy the third column of c into another variable.
Colon operator can be used for this purpose. If A is a given matrix, A(:,n) is the nth column of matrix A.
In your case, the third column can be stored inside variable 'var' ( 271x1 double vector ) on completion of the 'for' loop
var = c(:,3)

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by