Save a column as a variable

22 次查看(过去 30 天)
Liliana Sierra
Liliana Sierra 2017-12-13
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 CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by