Clear Filters
Clear Filters

Save a column as a variable

22 views (last 30 days)
Liliana Sierra
Liliana Sierra on 13 Dec 2017
Edited: Harish Ramachandran on 19 Dec 2017
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.

Answers (1)

Harish Ramachandran
Harish Ramachandran on 19 Dec 2017
Edited: Harish Ramachandran on 19 Dec 2017
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)

Categories

Find more on Function Creation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!