Effacer les filtres
Effacer les filtres

Save a column as a variable

22 vues (au cours des 30 derniers jours)
Liliana Sierra
Liliana Sierra le 13 Déc 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.

Réponses (1)

Harish Ramachandran
Harish Ramachandran le 19 Déc 2017
Modifié(e) : Harish Ramachandran le 19 Déc 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)

Catégories

En savoir plus sur Function Creation dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by