필터 지우기
필터 지우기

How to access specific data when using "getfield"

조회 수: 3 (최근 30일)
Artu
Artu 2012년 6월 27일
Hello all,
I am using the following code to analyse some data stored in a structure:
for i=1:10;
mean_value (i) = mean(getfield(Charge,strcat('Curve',int2str(i))));
end
"Charge" is the name of the structure, and "Curve" is each one of the 10 array of data inside it. So for this example, I get a vector with 10 elements that shows the average value of each group of data (the structure contains 10x(8670x1) elements). Now I want to take only the first 1416 elements of each array and to get its mean value. But I don't know how to do this.
Any suggestion? Thanks you so much!
Best regards.

답변 (3개)

Kye Taylor
Kye Taylor 2012년 6월 27일
If I understand your question, this may work...
for i=1:10;
myData(:,i) = getfield(Charge,strcat('Curve',int2str(i)));
end
mean_value = mean(myData);
meanValueFirstBunch = mean(myData(1:1416,:));

Leah
Leah 2012년 6월 27일
You can reference the field of a structure dynamically with Charge.Curve1 or Charge.('Curve1') Loren has some nice blog posts on structures http://blogs.mathworks.com/loren/2009/05/20/from-struct-to-dataset/
i=0
for fname=fieldnames(Charge)'
i=i+1;
mean_value(i)=mean(Charge.(char(fname))(1:1416));
end
  댓글 수: 1
Jan
Jan 2012년 6월 27일
fname{1} is more efficient than char(fname).

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2012년 6월 27일
for i = 1 : 10 mean_value(i) = mean(Charge.(str2num(i, 'Curve%d'))); end

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by