フィルターのクリア

Output of struct.fieldname

2 ビュー (過去 30 日間)
David C
David C 2015 年 12 月 16 日
コメント済み: David C 2015 年 12 月 17 日
"patient" is a 1x3 struct with "billing" being a fieldname. When I issue patient.billing, I get this:
>> patient.billing
ans =
127
ans =
28.500000000000000
ans =
23.300000000000001
Why is each value displayed separately? How do I collect the output into one variable?

採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 16 日
[patient.billing]
You are seeing "structure expansion", which is similar to cell array expansion. The output of
patient.billing
is the same as if you had typed
patient(1).billing, patient(2).billing, patient(3).billing, .... patient(end).billing
as a comma separated list. These will be treated as if you had typed separate arguments, so if for example you had used
sum(patient.billing)
that would be the same as
sum(127, 28.5, 23.3)
and it would then try (and fail) to use the 28.5 as the dimension number that sum expects for its second argument.
[patient.billing]
works because [] is the list building operator, and with comma separated lists is equivalent to horzcat()
horzcat(127, 28.5, 23.3)
being well defined
  6 件のコメント
Walter Roberson
Walter Roberson 2015 年 12 月 16 日
Which version are you using? The behaviour of expansion changed in R2015b.
David C
David C 2015 年 12 月 17 日
I am using R2014b.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by