gpt4 book ai didi

matlab - 什么时候应该在 Matlab 中使用 map 容器?

转载 作者:太空宇宙 更新时间:2023-11-03 20:03:25 25 4
gpt4 key购买 nike

<分区>

像 MathWorks 上的示例(见下文)那样使用 Maps 乍一看似乎很有用。但转念一想,它们是一种容器结构,就像 Matlab 的 struct 变量类型一样。我是 Maps 的新手,并且错过了何时使用它们而不是 structs 的优势 - 将问题分解为一些可衡量的参数:In what some use-cases使用 Mapsstructs 相比,使用的代码行数更快、代码行数更少吗?

来自 MathWorks 文档,例如:

months = {'Jan','Feb','Mar','Apr'};
rainfall = [327.2 368.2 197.6 178.4];
M = containers.Map(months,rainfall)

与结构类似的东西

months = {'Jan','Feb','Mar','Apr'};
rainfall = [327.2 368.2 197.6 178.4];
for ind=1:numel(months)
s.(months{ind})=rainfall(ind);
end

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com