필터 지우기
필터 지우기

Save a column as a variable

조회 수: 22 (최근 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 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