How do I name elements in a field of a structure?

조회 수: 5 (최근 30일)
Kim
Kim 2013년 3월 18일
I have a 1*1 structure with 4 fields. The structure was generated from anova1 so I didn't create it. One field is 33 *2 and I want to name each integer place with a string but I cannot seem to do this. Can anyone help?
Thanks! Kim
  댓글 수: 3
Kim
Kim 2013년 3월 18일
편집: Walter Roberson 2013년 3월 18일
st=
gnames: [40x2 char]
n: [1x40 double]
source: 'anova1'
means: [1x40 double]
df: 200
s: 1.1135
whos st
Name Size Bytes Class Attributes
st 1x1 1884 struct
Does this look right?
Walter Roberson
Walter Roberson 2013년 3월 18일
Okay, now what is it you want to do with the information?
It appears to me that if you want to know the group name for the group whose mean is st.means(K) then you would find it at st.gnames(K,:)

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 18일
A=struct('a',rand(33,2),'b',1,'c',2,'d',3) % your struct array
v=A.a
B.b=A.b
B.c=A.c
B.d=A.d
m=0
for k=1:33
for p=1:2
m=m+1
B.(sprintf('a%d',m))=v(k,p)
end
end

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 3월 18일
I'm not sure what you mean by naming each integer place with a string?
You can use
Structurename.appropriate_fieldname(I,J)
to access at matrix location (I,J) of the field. You can use
fieldnames(Structurename)
to find out what the field names are.
You cannot, however, do something like say that you want the variable "PLU" to refer to column 1 of the field -- not without extracting it from the structure.
If you need to be able to say things like "PLU(5) = 142031" and have it affect the contents of the structure field, then you need to use a "dataset", which I seem to recall is part of the Stats toolbox.
  댓글 수: 3
Kim
Kim 2013년 3월 18일
I'm new to Matlab, and can run all sorts of analyses but these things really get me. I'll try yours and Azzi's suggestions.
Image Analyst
Image Analyst 2013년 3월 18일
I see you accepted Azzi's answer. So is this all solved now?

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by