Foreach for containers.Map

版本 1.0.0.0 (2.0 KB) 作者: Jochen Rau
Provides a possibility to iterate over the items of a map
657.0 次下载
更新时间 2010/9/3

查看许可证

Matlab offers functionality for maps / dictionaries (a key-value store datatype). Iterating over a map can be cumbersome and that's where foreach steps in.

Using
resultmap = foreach(map, fctH)
calls function handle fctH with each item of the map. The result is stored in the resultmap which has the same keys as the original map.

If you have two or more datasets, and you want to process/plot them identically one function call is enough.
This turned out to be useful if you write a script processing one dataset. But then you want to compare to another ... either you can duplicate code or you iterate over the items. Foreach simplifies this iteration and keeps a readable key to the dataset ('which dataset has index 3?')

So long it's not much more than iterating over a cell array. However, if you combine foreach with some anonymous functions you get a much more powerful tool: foreach can call the function handle with the current iteration key so that one f.ex. can attach the corresponding legend-entry to a plot, using the corresponding axis ...

Try also 'help foreach' for more information and examples.

I hope you'll find it useful. Feedback is welcome!

引用格式

Jochen Rau (2024). Foreach for containers.Map (https://www.mathworks.com/matlabcentral/fileexchange/28630-foreach-for-containers-map), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2010a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Dictionaries 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0