-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MATLAB.DataFun. MeanSem MinSubs MATLAB.DataTypes. CatMode Cell2Mat DimensionFun FolderFun MATLAB.Graph2D MATLAB.Graph3D MATLAB.Graphics MATLAB.IOFun.DelimitedStrings2Table
- Loading branch information
1 parent
7aa2ba7
commit 0d473e4
Showing
87 changed files
with
2,358 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
classdef CatMode | ||
enumeration | ||
%Function的返回值为标量 | ||
Scalar | ||
%SplitDimensions为标量,且Function的返回值为类型、PackDimensions维度上尺寸均相同的数组 | ||
Linear | ||
%Function的返回值为数值、逻辑、字符或字段相同的结构体数组,且尺寸完全相同 | ||
EsNlcs | ||
%Function的返回值为数组,允许尺寸不同,但最终可以拼接成一整个大数组 | ||
CanCat | ||
%不符合上述任何条件,或返回值为函数句柄 | ||
DontCat | ||
end | ||
end |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function varargout = DFSuperCat(varargout,CM,SplitDimensions) | ||
import MATLAB.DataTypes.CatMode | ||
switch CM | ||
case CatMode.Scalar | ||
varargout=cellfun(@cell2mat,varargout,"UniformOutput",false); | ||
case CatMode.Linear | ||
if isempty(SplitDimensions) | ||
%这里不能使用varargout=horzcat(varargout{:}),因为varargout元胞里有可能是空的 | ||
varargout=cellfun(@(Out)vertcat(Out{:}),varargout,"UniformOutput",false); | ||
else | ||
varargout=cellfun(@(Out)cat(SplitDimensions,Out{:}),varargout,"UniformOutput",false); | ||
end | ||
case CatMode.CanCat | ||
varargout=cellfun(@MATLAB.DataTypes.Cell2Mat,varargout,"UniformOutput",false); | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function [Colors,Md] = ColorDistribute(NumberOfColorsToSuggest,ColorsToAvoid) | ||
arguments | ||
NumberOfColorsToSuggest(1,1)uint8 | ||
end | ||
arguments(Repeating) | ||
ColorsToAvoid(3,:)uint8 | ||
end | ||
ColorsToAvoid=gpuArray([ColorsToAvoid{:}]); | ||
SizeColor=width(ColorsToAvoid)+NumberOfColorsToSuggest; | ||
DimensionSplit=ceil(double(SizeColor)^(1/3)); | ||
if ~isempty(ColorsToAvoid) | ||
Cta=floor(double(ColorsToAvoid)/256*DimensionSplit); | ||
AvoidIndices=(Cta(1,:)*DimensionSplit+Cta(2,:))*DimensionSplit+Cta(3,:); | ||
else | ||
AvoidIndices=[]; | ||
end | ||
PossibleIndices=setdiff(0:DimensionSplit^3-1,AvoidIndices); | ||
StartPoints=PossibleIndices(randsample(length(PossibleIndices),NumberOfColorsToSuggest)); | ||
StartBs=mod(StartPoints,DimensionSplit); | ||
StartPoints=(StartPoints-StartBs)/DimensionSplit; | ||
StartGs=mod(StartPoints,DimensionSplit); | ||
StartPoints=(StartPoints-StartGs)/DimensionSplit; | ||
[Colors,Md]=TryCircle([[StartPoints;StartGs;StartBs]*255/(DimensionSplit-1) ColorsToAvoid],[SizeColor SizeColor],NumberOfColorsToSuggest); | ||
Colors=gather(uint8(Colors(:,1:NumberOfColorsToSuggest))); | ||
Md=sqrt(double(Md)); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function [M,I]=MinDistance(Colors,NumberOfVariables) | ||
Colors=double(Colors); | ||
NumberOfColors=width(Colors); | ||
Color1Matrix=repmat(Colors,1,1,NumberOfColors); | ||
Color2Matrix=repmat(permute(Colors,[1 3 2]),1,NumberOfColors,1); | ||
Distance=squeeze(sum((Color1Matrix-Color2Matrix).^2,1)); | ||
Distance(logical(eye(NumberOfColors)))=Inf; | ||
Distance(NumberOfVariables+1:end,NumberOfVariables+1:end)=Inf; | ||
[M,I]=min(Distance,[],"all","linear"); | ||
M=gather(M); | ||
I=gather(I); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function [Colors,Md]=TryCircle(Colors,SizeColors,NumberOfColorsToSuggest) | ||
Colors=int16(Colors); | ||
[Md,MinInd]=MinDistance(Colors,NumberOfColorsToSuggest); | ||
FirstTime=true; | ||
while true | ||
[Index1,Index2]=ind2sub(SizeColors,MinInd); | ||
if Index1<=NumberOfColorsToSuggest | ||
[Colors,M,MinIndNew]=TryColor(Colors,Index1,Md,NumberOfColorsToSuggest,MinInd,FirstTime); | ||
FirstTime=false; | ||
if M>Md||M==Md&&MinIndNew~=MinInd | ||
Md=M; | ||
MinInd=MinIndNew; | ||
continue; | ||
end | ||
end | ||
if Index2<=NumberOfColorsToSuggest | ||
[Colors,M,MinIndNew]=TryColor(Colors,Index2,Md,NumberOfColorsToSuggest,MinInd,FirstTime); | ||
FirstTime=false; | ||
if M>Md||M==Md&&MinIndNew~=MinInd | ||
Md=M; | ||
MinInd=MinIndNew; | ||
continue; | ||
end | ||
end | ||
break; | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function [Colors,Md,MinInd]=TryColor(Colors,Index,Md,NumberOfColorsToSuggest,MinInd,FirstTime) | ||
persistent RGBs Untried | ||
if isempty(RGBs) | ||
RGBs=gpuArray(int32(cat(4,repmat((0:255)',1,256,256),repmat(0:255,256,1,256),repmat(shiftdim(0:255,-1),256,256)))); | ||
end | ||
if FirstTime | ||
Untried=true(256,256,256,"gpuArray"); | ||
end | ||
Colors=int32(Colors); | ||
PossibleDistances=sum((RGBs-permute(Colors(:,[1:Index-1 Index+1:end]),[3 4 5 1 2])).^2,4); | ||
Candidates=find(all(PossibleDistances>Md,5)&Untried); | ||
if isempty(Candidates) | ||
Candidates=find(all(PossibleDistances==Md,5)&Untried); | ||
end | ||
if ~isempty(Candidates) | ||
if numel(Candidates)>1 | ||
NewColor=gather(randsample(Candidates,1)); | ||
else | ||
NewColor=gather(Candidates); | ||
end | ||
[NewR,NewG,NewB]=ind2sub([256 256 256],NewColor); | ||
NewColor=squeeze(RGBs(NewR,NewG,NewB,:)); | ||
Colors(:,Index)=NewColor; | ||
[M,MinInd]=MinDistance(Colors,NumberOfColorsToSuggest); | ||
if M>Md | ||
Untried=true(256,256,256); | ||
Untried(NewColor(1)+1,NewColor(2)+1,NewColor(3)+1)=false; | ||
Md=M; | ||
else | ||
Untried(NewColor(1)+1,NewColor(2)+1,NewColor(3)+1)=false; | ||
end | ||
end | ||
end |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
function V = Version | ||
V.Me='2.4.0'; | ||
V.Me='2.5.0'; |
Oops, something went wrong.