structure indices in one line

3 ビュー (過去 30 日間)
Robert
Robert 2012 年 10 月 1 日
I would like to extract values from a structure. I know how to do it in two lines of code, but is it possible in one?
temp = urlAuthsMap.values;
temp{1}
My solution would have been something like [urlAuthsMap.values]{1} but that doesn't work.
>> temp = urlAuthsMap.values
Columns 1 through 11
{1x4 cell} {1x1 cell} {1x3 cell} ...
>> temp{1}
ans =
'S. A. Abraham' 'H. A. Bodner' 'C. G. Harrington' 'R. C. White Jr.'

採用された回答

Matt Fig
Matt Fig 2012 年 10 月 1 日
編集済み: Matt Fig 2012 年 10 月 1 日
V = values(urlAuthsMap,KH); % KH is the key you want. See key.
From the link you showed above .... ;-)
  1 件のコメント
Robert
Robert 2012 年 10 月 19 日
Thanks a lot for your answer by email. i'll paste it in below
As far as I know, there is no way to index into newMap the way you want to.
keySet = {'Jun','Jul','Aug'}; valueSet = [ 69.9, 32.3, 37.3]; newMap = containers.Map(keySet,valueSet); values(newMap,keySet(1)) % This is how to do it.
As far as your other example, try this:
a{1} = [1,2,3] a{2}=[4,5,6]
a{2}(1)

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2012 年 10 月 1 日
編集済み: Image Analyst 2012 年 10 月 1 日
urlAuthsMap.values = {'S. A. Abraham', 'H. A. Bodner', 'C. G. Harrington', 'R. C. White Jr.'}
% Here's how to do it.
caName1 = urlAuthsMap.values(1) % This is a cell.
strName1 = urlAuthsMap.values{1} % This is a string.
  1 件のコメント
Robert
Robert 2012 年 10 月 1 日
Thanks, I've tried this but am getting errors for both. I realized that maybe my map object is special and doesn't work like a normal cell array. Any ideas?
urlAuthsMap.values{1} Error using containers.Map/values Invalid input for argument 2 (rhs2): Value must be 'cell'.
>> urlAuthsMap.values(1) Error using containers.Map/values Invalid input for argument 2 (rhs2): Value must be 'cell'.

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by