Skip to content

Commit 78cb922

Browse files
author
埃博拉酱
committed
v19.6.0
1 parent fa58224 commit 78cb922

File tree

11 files changed

+117
-7
lines changed

11 files changed

+117
-7
lines changed

+MATLAB/+DataFun/MaxSubs.m

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
%[text] 返回数组的最大值以及所在的坐标。
2+
%[text] MATLAB自带的max函数只能返回多维数组最大值的线性索引。本函数一口气返回最大值以及多维坐标,方便易用
3+
%[text] ## 语法
4+
%[text] ```matlabCodeExample
5+
%[text] import MATLAB.DataFun.MaxSubs
6+
%[text]
7+
%[text] [Value,S1,S2,…,Sn]=MaxSubs(Data);
8+
%[text] %返回整个多维数组的全局最大值及其坐标
9+
%[text]
10+
%[text] [___]=MaxSubs(Data,Dimensions);
11+
%[text] %仅在指定维度上取最大值,返回指定维度上的最大值坐标
12+
%[text]
13+
%[text] [___]=MaxSubs(Data,Dimensions,K);
14+
%[text] %额外指定要返回几个最大值
15+
%[text] ```
16+
%[text] ## 示例
17+
%[text] ```matlabCodeExample
18+
%[text] %对于有多个最大值的数组,返回线性索引最小的那个位置的坐标:
19+
%[text] [M,S1,S2]=MATLAB.DataFun.MaxSubs([9 9 1;1 4 4;9 8 9])
20+
%[text] %{
21+
%[text] M =
22+
%[text]
23+
%[text] 9
24+
%[text]
25+
%[text]
26+
%[text] S1 =
27+
%[text]
28+
%[text] 1
29+
%[text]
30+
%[text]
31+
%[text] S2 =
32+
%[text]
33+
%[text] 1
34+
%[text] %}
35+
%[text] %还可以指定运算维度。如将一个3维数组的后两维求最大值和下标,则返回的最大值和下标都是沿第1维的向量,且只返回最大值在后两维的下标
36+
%[text] [M,S2,S3]=MATLAB.DataFun.MaxSubs(rand(3,3,3),[2 3])
37+
%[text] %坐标维度输出顺序与输入的指定Dimension有关
38+
%[text] [M,S3,S2]=MATLAB.DataFun.MaxSubs(rand(3,3,3),[3 2])
39+
%[text] ```
40+
%[text] ## 输入参数
41+
%[text] Data,要寻找最大值的多维数组。
42+
%[text] Dimensions(1,:)=\[\],要取最大值的维度。如果设为空,将把所有维度都参与运算,即返回单一标量作为整个数组的最大值,并按顺序返回该最大值各个维度的坐标。
43+
%[text] K=1,要取几个最大值。
44+
%[text] ## 返回值
45+
%[text] Value,最大值。在Dimensions(1)指定的维度上(如果Dimensions为空,则在第1维度上)长度为K,在Dimensions(2:end)指定的维度上(如果Dimensions为空,则在2:ndims(Data)维度上)长度为1,在其它维度上长度与Data相同。
46+
%[text] S1,S2, …, Sn,最大值所在的位置中,线性索引最小的那个位置的坐标。每个返回值依次代表各维度的坐标。如果指定了Dimensions不为空,将只包含Dimensions维度的坐标`,并按照Dimensions指定的顺序排列输出。这些坐标值数组的尺寸与Value相同,一一对应。`
47+
%[text] **See also** [max](<matlab:doc max>) [maxk](<matlab:doc maxk>)
48+
function [Value,varargout] = MaxSubs(Data,Dimensions,K)
49+
arguments
50+
Data
51+
Dimensions(1,:)=[]
52+
K=1
53+
end
54+
NumDimensions=numel(Dimensions);
55+
if nargout>1
56+
if K>1
57+
switch NumDimensions
58+
case 0
59+
[Value,LinearIndex]=maxk(Data(:),K);
60+
[varargout{1:max(nargout-1,ndims(Data))}]=ind2sub(size(Data),LinearIndex);
61+
case 1
62+
[Value,varargout{1}]=maxk(Data,K,Dimensions);
63+
otherwise
64+
OtherDimensions=setdiff(1:max([Dimensions,ndims(Data)]),Dimensions);
65+
Permuter=[Dimensions,OtherDimensions];
66+
DimensionsSize=size(Data,Dimensions);
67+
[Value,LinearIndex]=maxk(reshape(permute(Data,Permuter),[prod(DimensionsSize),ones(1,NumDimensions-1),size(Data,OtherDimensions)]),K,1);
68+
Value=ipermute(Value,Permuter);
69+
[varargout{1:NumDimensions}]=ind2sub(DimensionsSize,ipermute(LinearIndex,Permuter));
70+
end
71+
else
72+
switch NumDimensions
73+
case 0
74+
[Value,LinearIndex]=max(Data(:));
75+
[varargout{1:max(nargout-1,ndims(Data))}]=ind2sub(size(Data),LinearIndex);
76+
case 1
77+
[Value,varargout{1}]=max(Data,[],Dimensions);
78+
otherwise
79+
%必需ndims,不能用nargout,否则ind2sub会把后面维度都乘起来
80+
DimIndex=1:max([ndims(Data),Dimensions]);
81+
82+
[Value,LinearIndex]=max(Data,[],Dimensions,'linear');
83+
%max的linear是全局线性坐标,而不是指定维度上的线性坐标
84+
85+
[varargout{DimIndex}]=ind2sub(size(Data,DimIndex),LinearIndex);
86+
varargout=varargout(Dimensions);
87+
end
88+
end
89+
elseif K>1
90+
switch NumDimensions
91+
case 0
92+
Value=maxk(Data(:),K);
93+
case 1
94+
Value=maxk(Data,K,Dimensions);
95+
otherwise
96+
OtherDimensions=setdiff(1:max([Dimensions,ndims(Data)]),Dimensions);
97+
Permuter=[Dimensions,OtherDimensions];
98+
Value=ipermute(maxk(reshape(permute(Data,Permuter),[prod(size(Data,Dimensions)),ones(1,NumDimensions-1),size(Data,OtherDimensions)]),K,1),Permuter);
99+
end
100+
elseif NumDimensions
101+
Value=max(Data,[],Dimensions);
102+
else
103+
Value=max(Data(:));
104+
end
105+
106+
%[appendix]{"version":"1.0"}
107+
%---

+MATLAB/+DataFun/MaxSubs.mlx

-6.86 KB
Binary file not shown.
-24 KB
Binary file not shown.

+MATLAB/+internal/提权操作C.exe

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ package*
1313
**/obj
1414
**/*.deps.json
1515
/+MATLAB/+internal/private/libwebp_debug.dll
16-
node_modules
16+
node_modules
17+
deploymentLog.html
18+
resources/4*

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
- [+SpecFun](#specfun) 穷举、椭圆周长
2626
- [+SupportPkg](#supportpkg) 一键获取MATLAB硬件支持包
2727
- [+UITools](#uitools) 文件打开和保存对话框
28-
- 还有一些尚未归类的工具函数直接放在MATLAB包下
28+
- 还有一些尚未归类的工具函数直接放在MATLAB命名空间下
2929

3030
每个代码文件内部都有详细文档,可以用doc命令查看,此处仅列出函数签名和类功能简介。
3131
# +MATLAB

resources/project/8tUU0HZQD5VYGkN5lnFExWT9CXo/q0dZ3MxP_azgwkHbYe_78t9S6rod.xml renamed to resources/project/8tUU0HZQD5VYGkN5lnFExWT9CXo/85J8wcgvzU1j2A7gY095eoIG6zQd.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version='1.0' encoding='UTF-8'?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<Info>
33
<Category UUID="FileClassCategory">
44
<Label UUID="design"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Info location="MaxSubs.m" type="File"/>

resources/project/8tUU0HZQD5VYGkN5lnFExWT9CXo/q0dZ3MxP_azgwkHbYe_78t9S6rop.xml

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Info ToolboxConfigModel="{&quot;entries&quot;:[{&quot;content&quot;:{&quot;appGalleryLabel&quot;:{&quot;content&quot;:{&quot;categoryID&quot;:&quot;Deployment_Category_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;,&quot;labelID&quot;:&quot;Deployment_ToolboxAppGalleryFiles_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectLabel&quot;,&quot;uuid&quot;:&quot;dcd2a16f-df2b-46eb-a9ba-f5ca4a560b0e&quot;},&quot;authorEmail&quot;:&quot;[email protected]&quot;,&quot;authorName&quot;:&quot;埃博拉酱&quot;,&quot;authorOrganization&quot;:&quot;一致行动党&quot;,&quot;description&quot;:&quot;埃博拉酱的MATLAB扩展工具箱,提供一系列MATLAB内置函数所欠缺,但却常用的增强功能。还替官方修复了许多内置函数的bug。\n\n目录\n本工具箱中所有函数均在MATLAB命名空间下,使用前需import。\n\n+MATLAB\n+Containers 实现多种STL容器\n+Database MariaDB JDBC 数据库相关操作\n+DataFun 数值统计操作\n+DataTypes 元胞、表格、结构等特殊容器类型的复杂操作\n+ElFun 数值变换\n+ElMat 数组形状变换\n+General 变量、路径、工作区操作\n+Graphics 图窗和绘图操作\n+ImageSci 读入图像\n+IO 文件和ZIP档案操作\n+IOFun 文件、网络、内存读写相关\n+Lang 函数使用、定义、异常工具、语言功能\n+Ops 逻辑和集合操作\n+Project 工程相关\n+RandFun 随机概率分布洗牌\n+SpecFun 穷举、椭圆周长\n+SupportPkg 一键获取MATLAB硬件支持包\n+UITools 文件打开和保存对话框\n还有一些尚未归类的工具函数直接放在MATLAB包下&quot;,&quot;gettingStartedGuideLabel&quot;:{&quot;content&quot;:{&quot;categoryID&quot;:&quot;Deployment_Category_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;,&quot;labelID&quot;:&quot;Deployment_GettingStartedGuideFile_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectLabel&quot;,&quot;uuid&quot;:&quot;54e02641-bdd9-45c8-8f79-98d1404a077e&quot;},&quot;maxRelease&quot;:&quot;R2025a&quot;,&quot;minRelease&quot;:&quot;R2024b&quot;,&quot;outputFileName&quot;:&quot;埃博拉酱的MATLAB扩展.mltbx&quot;,&quot;outputFolder&quot;:&quot;/&quot;,&quot;requiredAddons&quot;:[{&quot;content&quot;:{&quot;addonName&quot;:&quot;埃博拉酱的MATLAB扩展&quot;,&quot;earliestVersion&quot;:&quot;19.5.0&quot;,&quot;excluded&quot;:true,&quot;latestVersion&quot;:&quot;19.5.0&quot;,&quot;uniqueId&quot;:&quot;d0a3672f-3b10-424c-868b-3cb64e588934&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.RequiredAddon&quot;,&quot;uuid&quot;:&quot;6ffb91a3-ac83-466d-8f86-83ed768b864b&quot;},{&quot;content&quot;:{&quot;addonName&quot;:&quot;埃博拉酱的文本分析工具箱&quot;,&quot;earliestVersion&quot;:&quot;1.0.4&quot;,&quot;excluded&quot;:true,&quot;latestVersion&quot;:&quot;1.0.4&quot;,&quot;uniqueId&quot;:&quot;49f10a66-12e1-4a02-bc1c-fef8447af60b&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.RequiredAddon&quot;,&quot;uuid&quot;:&quot;55674fe5-5066-4b73-84c6-378d97d6e7b4&quot;}],&quot;summary&quot;:&quot;提供许多内置函数的bug修复(是的,我们有在替官方修bug)、功能升级版,以及一系列内置函数所欠缺,但却常用的增强功能(部分功能仅支持Windows系统)。例如,MariaDB数据库相关操作、序列化字节和反序列化、统一各坐标区的XYZC轴范围、斐波那契插值、全局键值对……&quot;,&quot;supportedPlatforms&quot;:[&quot;Windows&quot;,&quot;Linux&quot;,&quot;Mac&quot;,&quot;MatlabOnline&quot;],&quot;toolboxFolder&quot;:&quot;/&quot;,&quot;toolboxImgLabel&quot;:{&quot;content&quot;:{&quot;categoryID&quot;:&quot;Deployment_Category_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;,&quot;labelID&quot;:&quot;Deployment_ToolboxImageFile_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectLabel&quot;,&quot;uuid&quot;:&quot;f1dbb896-c80e-4ac0-a242-c9be3493bf94&quot;},&quot;toolboxName&quot;:&quot;埃博拉酱的MATLAB扩展&quot;,&quot;toolboxVersion&quot;:&quot;19.5.2&quot;,&quot;uniqueId&quot;:&quot;d0a3672f-3b10-424c-868b-3cb64e588934&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ToolboxConfiguration&quot;,&quot;uuid&quot;:&quot;d1acd8bf-3e8b-415c-8ec3-9d9be70efeec&quot;},{&quot;content&quot;:{},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectStateValidationIssueList&quot;,&quot;uuid&quot;:&quot;ff21a168-15ac-46c8-be16-7b0924b7c584&quot;}],&quot;packageUris&quot;:[&quot;http://schema.mathworks.com/mf0/deployment_toolbox_model/1.0.0&quot;],&quot;version&quot;:&quot;1.0&quot;}" displayName="Toolbox" lastAccessed="1745047745920" taskID="4ac4332f-d563-4b2e-b9d6-2490b507ccef" type="Toolbox" uniqueId="f615531a-5e2a-4e3c-8c16-f56da93b5f57"/>
2+
<Info ToolboxConfigModel="{&quot;entries&quot;:[{&quot;content&quot;:{&quot;appGalleryLabel&quot;:{&quot;content&quot;:{&quot;categoryID&quot;:&quot;Deployment_Category_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;,&quot;labelID&quot;:&quot;Deployment_ToolboxAppGalleryFiles_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectLabel&quot;,&quot;uuid&quot;:&quot;dcd2a16f-df2b-46eb-a9ba-f5ca4a560b0e&quot;},&quot;authorEmail&quot;:&quot;[email protected]&quot;,&quot;authorName&quot;:&quot;埃博拉酱&quot;,&quot;authorOrganization&quot;:&quot;一致行动党&quot;,&quot;description&quot;:&quot;埃博拉酱的MATLAB扩展工具箱,提供一系列MATLAB内置函数所欠缺,但却常用的增强功能。还替官方修复了许多内置函数的bug。\n\n个别功能最高要求 MATLAB R2024b 版本才能正常工作,但低版本一般可以运行大部分功能。\n\nView 埃博拉酱的 MATLAB 扩展 Extension on File Exchange\n\n目录\n本工具箱中所有函数均在MATLAB命名空间下,使用前需import。\n\n+MATLAB\n+Containers 实现多种STL容器\n+Database MariaDB JDBC 数据库相关操作\n+DataFun 数值统计操作\n+DataTypes 元胞、表格、结构等特殊容器类型的复杂操作\n+ElFun 数值变换\n+ElMat 数组形状变换\n+General 变量、路径、工作区操作\n+Graphics 图窗和绘图操作\n+ImageSci 读入图像\n+IO 文件和ZIP档案操作\n+IOFun 文件、网络、内存读写相关\n+Lang 函数使用、定义、异常工具、语言功能\n+MixIn 索引相关功能\n+Ops 逻辑和集合操作\n+Project 工程相关\n+RandFun 随机概率分布洗牌\n+SpecFun 穷举、椭圆周长\n+SupportPkg 一键获取MATLAB硬件支持包\n+UITools 文件打开和保存对话框\n还有一些尚未归类的工具函数直接放在MATLAB命名空间下&quot;,&quot;gettingStartedGuideLabel&quot;:{&quot;content&quot;:{&quot;categoryID&quot;:&quot;Deployment_Category_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;,&quot;labelID&quot;:&quot;Deployment_GettingStartedGuideFile_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectLabel&quot;,&quot;uuid&quot;:&quot;54e02641-bdd9-45c8-8f79-98d1404a077e&quot;},&quot;maxRelease&quot;:&quot;R2025a&quot;,&quot;minRelease&quot;:&quot;R2024b&quot;,&quot;outputFileName&quot;:&quot;埃博拉酱的MATLAB扩展.mltbx&quot;,&quot;outputFolder&quot;:&quot;/&quot;,&quot;requiredAddons&quot;:[{&quot;content&quot;:{&quot;addonName&quot;:&quot;埃博拉酱的MATLAB扩展&quot;,&quot;earliestVersion&quot;:&quot;19.5.0&quot;,&quot;excluded&quot;:true,&quot;latestVersion&quot;:&quot;19.5.0&quot;,&quot;uniqueId&quot;:&quot;6ffb91a3-ac83-466d-8f86-83ed768b864b&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.RequiredAddon&quot;,&quot;uuid&quot;:&quot;b4e59513-d8f9-4065-b45c-e93973ff559e&quot;},{&quot;content&quot;:{&quot;addonName&quot;:&quot;埃博拉酱的文本分析工具箱&quot;,&quot;earliestVersion&quot;:&quot;1.0.4&quot;,&quot;excluded&quot;:true,&quot;latestVersion&quot;:&quot;1.0.4&quot;,&quot;uniqueId&quot;:&quot;55674fe5-5066-4b73-84c6-378d97d6e7b4&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.RequiredAddon&quot;,&quot;uuid&quot;:&quot;bba0ed0d-9927-4afe-9a7b-1aee97afa5b0&quot;}],&quot;summary&quot;:&quot;提供许多内置函数的bug修复(是的,我们有在替官方修bug)、功能升级版,以及一系列内置函数所欠缺,但却常用的增强功能(部分功能仅支持Windows系统)。例如,任意维度polyfit,MariaDB数据库相关操作、序列化字节和反序列化、统一各坐标区的XYZC轴范围……&quot;,&quot;supportedPlatforms&quot;:[&quot;Windows&quot;,&quot;Linux&quot;,&quot;Mac&quot;,&quot;MatlabOnline&quot;],&quot;toolboxFolder&quot;:&quot;/&quot;,&quot;toolboxImgLabel&quot;:{&quot;content&quot;:{&quot;categoryID&quot;:&quot;Deployment_Category_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;,&quot;labelID&quot;:&quot;Deployment_ToolboxImageFile_f615531a-5e2a-4e3c-8c16-f56da93b5f57&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectLabel&quot;,&quot;uuid&quot;:&quot;f1dbb896-c80e-4ac0-a242-c9be3493bf94&quot;},&quot;toolboxName&quot;:&quot;埃博拉酱的MATLAB扩展&quot;,&quot;toolboxVersion&quot;:&quot;19.6.0&quot;,&quot;uniqueId&quot;:&quot;d0a3672f-3b10-424c-868b-3cb64e588934&quot;},&quot;type&quot;:&quot;deployment.toolbox.model.ToolboxConfiguration&quot;,&quot;uuid&quot;:&quot;d1acd8bf-3e8b-415c-8ec3-9d9be70efeec&quot;},{&quot;content&quot;:{},&quot;type&quot;:&quot;deployment.toolbox.model.ProjectStateValidationIssueList&quot;,&quot;uuid&quot;:&quot;ff21a168-15ac-46c8-be16-7b0924b7c584&quot;}],&quot;packageUris&quot;:[&quot;http://schema.mathworks.com/mf0/deployment_toolbox_model/1.0.0&quot;],&quot;version&quot;:&quot;1.0&quot;}" displayName="Toolbox" lastAccessed="1747723798225" taskID="4ac4332f-d563-4b2e-b9d6-2490b507ccef" type="Toolbox" uniqueId="f615531a-5e2a-4e3c-8c16-f56da93b5f57"/>

toolbox.ignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ README.md
4141
**/*.pdb
4242
**/*.exp
4343
**/*.lib
44-
deploymentLog.html
44+
deploymentLog.html
45+
toolbox.ignore

0 commit comments

Comments
 (0)