How to retrieve a table entry using row name?

조회 수: 121(최근 30일)
KAE
KAE 2020년 4월 10일
댓글: KAE 2020년 4월 10일
The function anova returns a 3x5 table and I would like retreive the value from the row named Model and column named pValue. How do I do this? I don't know how to retreive a table entry by the row name, only by the row number.
mr = anova(lm,'summary')

채택된 답변

dpb
dpb 2020년 4월 10일
It's a table; use the curlies "{}" to dereference row names to return the content of the row or regular paren's "()" to return a table:
Used example for anova to illustrate w/o your data to replicate--
load hospital
tbl = table(hospital.Age,hospital.Sex,hospital.BloodPressure(:,2), ...
'VariableNames',{'Age','Sex','BloodPressure'});
tbl.Sex = categorical(tbl.Sex);
mdl = fitlm(tbl,'BloodPressure ~ Sex + Age'); simplified model to remove nonlinear terms
>> tAnova=anova(mdl,'summary')
tAnova =
5×5 table
SumSq DF MeanSq F pValue
______ __ ______ _______ ________
Total 4757.8 99 48.059
Model 243.8 2 121.9 2.6194 0.077994
Residual 4514 97 46.537
. Lack of fit 1514 40 37.851 0.71916 0.86306
. Pure error 3000 57 52.632
>>
>> tAnova('Total',:) % retrieve Total SSQ by row name as table
ans =
1×5 table
SumSq DF MeanSq F pValue
______ __ ______ ___ ______
Total 4757.8 99 48.059 NaN NaN
>>
>> tAnova{'Total',:} % retrieve as array of values only
ans =
1.0e+03 *
4.7578 0.0990 0.0481 NaN NaN
>>
See the detailed description of addressing tables that is in the lind from "See Also" for table for all the skinny on all the ways to address tables.
  댓글 수: 1
KAE
KAE 2020년 4월 10일
In my case, I wanted
mr{'Model', 'pValue'}
Thanks!

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

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by