How to convert 'Structure' ?!

조회 수: 1 (최근 30일)
Mariam Sheha
Mariam Sheha 2013년 6월 29일
Hi everybody;
I am trying to get feature value out of structure array..
for example:
glcms = graycomatrix(CG,'Offset',[0 1]);
Cont_RGB = graycoprops(glcms,'Contrast');
F=Cont_RGB;
F= Contrast: 0.2546 % i wana to remove word contrast and get the number only!
How can i get the number?
Thank you

채택된 답변

Walter Roberson
Walter Roberson 2013년 6월 30일
If your
Cont_RGB = graycoprops(glcms,'Contrast');
is returning a Cont_RGB which is a structure array, and you want to extract the field named "Contrast" from the first member of that structure array, you would use
Cont_RGB(1).Contrast
and in the cast where the structure array only has a single member (so Cont_RGB(2) does not exist) then you can abbreviate that to
Cont_RGB.Contrast
In the above, the period is part of the syntax.
If Cont_RGB is a structure array, so Cont_RGB(2).Contrast and so on exist, and you are trying to get a vector equivalent to
[Cont_RGB(1).Contrast Cont_RGB(2).Contrast Cont_RGB(3).Contrast ....]
then use
[Cont_RGB.Contrast]
In this, the [] and the period are part of the syntax.
  댓글 수: 1
Mariam Sheha
Mariam Sheha 2013년 6월 30일
yes, it works thanks alo0o0ot :)

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

추가 답변 (2개)

Matthew Eicholtz
Matthew Eicholtz 2013년 6월 29일
  댓글 수: 2
Mariam Sheha
Mariam Sheha 2013년 6월 29일
can you tell me what does 'F','contrast' represent
Walter Roberson
Walter Roberson 2013년 6월 30일
Cont_RGB = graycoprops(glcms,'Contrast');
Cont_RGB.Contrast
The "." between the variable name and "Contrast" is literal, part of the syntax.

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


Image Analyst
Image Analyst 2013년 6월 29일
theNumber = F.Contrast;
  댓글 수: 3
Image Analyst
Image Analyst 2013년 6월 30일
All 3 people answered with the same thing, and you accepted the third response, so I think we all knew what you meant. Hopefully you're now using Walter's answer, and are not doing unnecessary operations like converting to a cell array and then converting the cell array to a matrix. You may find it helpful to read the FAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
Mariam Sheha
Mariam Sheha 2013년 6월 30일
Thanks for you all replaying me,
Walter's mentioned his answer,and so i get the point once i read discussion..
yes i do using the method now instead of using useless operation..
Also, Thanks for the doc. it's helpful
Really you are all helpful and creative...:)

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by