Retrieving an array of values for an array of keys from a containers.map object

조회 수: 8 (최근 30일)
My code uses a containers.map object smap. I currently have the following inside a loop with over 6 million iterations:
val(i) = smap(key(i))
I'd like to take it out of the loop to make it faster - I can make a cell array of the (string) keys called keyList, and I tried
val_arr = cellfun(@(x), smap(x), keyList, 'UniformOutput', 'false')
which works but is actually a few seconds slower than just calling it inside the loop. Can you suggest how I might do this faster?

답변 (1개)

Walter Roberson
Walter Roberson 2011년 9월 28일
val_arr = cellfun(@(x), smap(x), keyList, 'UniformOutput', 'false')
is a syntax error, as it has no function body for the anonymous function.
If you remove the comma after @(x) then it becomes valid.
  댓글 수: 1
Joanne
Joanne 2011년 9월 28일
Sorry, that was a typing-from-memory error on my part (I don't have the code with me). The function _did_ work, but was slower. Pretend I wrote:
val_arr = cellfun(@(x) smap(x), keyList, 'UniformOutput', 'false')

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by