Electrolyzer modelling toolbox
MATLAB Central - File Exchange - rating:5.0 (RSS)
[](https://se.mathworks.com/matlabcentral/fileexchange/117175-electrolyzer-modelling-toolbox)### GENERAL DESCRIPTIONThis toolbox is a Matlab tool for electrolysis modelling, for both PEM and alkaline systems. Main functionality is in parametrization of the UI curvebased on measured data. This toolbox aims to simplify the process and provide easy-to-use commands for quickly determining the UI curve parameter values and their margins of uncertainty.Since version 2.0.0, dynamic modeling functionality has been added, being capable of fitting model parameters from time-dependent data sets and using the fit parameters to simulate dynamic voltage response to arbitrarycurrent waveforms.---### INSTALLATIONMATLAB needs to be installed on the computer for the user to be able toinstall the electrolyzer modelling toolbox. Following steps install thetoolbox for that matlab installation:1. Download the provided electrolyzerModellingToolbox.mltbx file from the releases page. - Double click on the .mltbx file to initiate installation.2. Once the installation completes the toolbox functions are usable in all matlab projects---### AUTHORS AND CONTACTSPietari PuranenJunior researcher at the Lappeenranta-Lahti University of Technology LUTEmail: Pietari.Puranen@lut.fiLauri JärvinenJunior researcher at the Lappeenranta-Lahti University of Technology LUTEmail: Lauri.Jarvinen@lut.fi---### AKNOWLEDGEMENTSMarchov Chain Monte Carlo (MCMC) tools provided by Marko Laine have been used for the determination of uncertainty in curve fitting when using the particleswarm optimization method. The licensing for the tools can be foundunder ./Utils/mcmcstat/LICENSE.txtThe Academy of Finland is acknowledged for the main financial support ofthe Research of Power Quality Effect on Water Electrolyzer Operation (POQELYZER) project.
MATLAB Central - File Exchange - rating:5.0 (RSS)
[](https://se.mathworks.com/matlabcentral/fileexchange/117175-electrolyzer-modelling-toolbox)### GENERAL DESCRIPTIONThis toolbox is a Matlab tool for electrolysis modelling, for both PEM and alkaline systems. Main functionality is in parametrization of the UI curvebased on measured data. This toolbox aims to simplify the process and provide easy-to-use commands for quickly determining the UI curve parameter values and their margins of uncertainty.Since version 2.0.0, dynamic modeling functionality has been added, being capable of fitting model parameters from time-dependent data sets and using the fit parameters to simulate dynamic voltage response to arbitrarycurrent waveforms.---### INSTALLATIONMATLAB needs to be installed on the computer for the user to be able toinstall the electrolyzer modelling toolbox. Following steps install thetoolbox for that matlab installation:1. Download the provided electrolyzerModellingToolbox.mltbx file from the releases page. - Double click on the .mltbx file to initiate installation.2. Once the installation completes the toolbox functions are usable in all matlab projects---### AUTHORS AND CONTACTSPietari PuranenJunior researcher at the Lappeenranta-Lahti University of Technology LUTEmail: Pietari.Puranen@lut.fiLauri JärvinenJunior researcher at the Lappeenranta-Lahti University of Technology LUTEmail: Lauri.Jarvinen@lut.fi---### AKNOWLEDGEMENTSMarchov Chain Monte Carlo (MCMC) tools provided by Marko Laine have been used for the determination of uncertainty in curve fitting when using the particleswarm optimization method. The licensing for the tools can be foundunder ./Utils/mcmcstat/LICENSE.txtThe Academy of Finland is acknowledged for the main financial support ofthe Research of Power Quality Effect on Water Electrolyzer Operation (POQELYZER) project.
📡 MATLAB Central - File Exchange - rating:5.0 | truncAxis (break X/Y axis | 截断坐标轴)
Basic usagetruncAxis(gca, 'X', [x1, x2])truncAxis(gca, 'Y', [y1, y2])truncAxis(gca, 'X', [x1, x2], 'Y', [y1, y2]) Where:x1, x2: break points on X-axis, satisfying XLim(1) < x1 < x2 < XLim(2)y1, y2: break points on Y-axis, satisfying YLim(1) < y1 < y2 < YLim(2)Demo 1X = linspace(0, 2*pi, 100);Y = exp(.3*X).*sin(3*X);scatter(X, Y, 'LineWidth',1);set(gca, 'Box','on', 'NextPlot','add', 'LineWidth',1.5, ... 'FontName','Times New Roman', 'FontSize',15, ... 'XLim',[0, 6], 'YLim',[-6, 6], 'XColor','r','YColor','b', ... 'XMinorTick','on', 'YMinorTick','on', 'TickDir','out', 'TickLength',[.005,.001]);truncAxis('X',[4, 4.5], 'Y',[2, 3], 'XResize','on', 'YResize','on')legendDemo 2% Generate sample dataData = [randi([20, 35], [5, 1]), randi([160, 190], [5, 1])];err = rand([5, 2]) .* 5;hold onbarHdl = bar(Data, 'BarWidth', 1, 'LineWidth',1);% Customize bar colors and transparencybarHdl(1).FaceColor = [153, 153, 253] ./ 255;barHdl(2).FaceColor = [255, 153, 154] ./ 255;barHdl(1).FaceAlpha = 0.9;barHdl(2).FaceAlpha = 0.9;% Render and customize error barserrorbar(barHdl(1).XEndPoints, Data(:, 1), err(:, 1), ... 'LineStyle', 'none', 'Color', 'k', 'LineWidth', 1);errorbar(barHdl(2).XEndPoints, Data(:, 2), err(:, 2), ... 'LineStyle', 'none', 'Color', 'k', 'LineWidth', 1);% Axes styling and label customizationax = gca;ax.YLim = [0, 200];ax.LineWidth = 1;ax.TickLength = [0.005, 0.001];ax.Box = 'on';ax.FontSize = 13;ax.XTick = 1:5;ax.XTickLabel = {'A', 'B', 'C', 'D', 'E'};axMat = truncAxis('Y', [50, 155]);axMat(1).Children(end).BaseLine.Color = 'none';% Add legendlegend({'AAAAA', 'BBBBB'}, 'FontSize', 13);
Basic usagetruncAxis(gca, 'X', [x1, x2])truncAxis(gca, 'Y', [y1, y2])truncAxis(gca, 'X', [x1, x2], 'Y', [y1, y2]) Where:x1, x2: break points on X-axis, satisfying XLim(1) < x1 < x2 < XLim(2)y1, y2: break points on Y-axis, satisfying YLim(1) < y1 < y2 < YLim(2)Demo 1X = linspace(0, 2*pi, 100);Y = exp(.3*X).*sin(3*X);scatter(X, Y, 'LineWidth',1);set(gca, 'Box','on', 'NextPlot','add', 'LineWidth',1.5, ... 'FontName','Times New Roman', 'FontSize',15, ... 'XLim',[0, 6], 'YLim',[-6, 6], 'XColor','r','YColor','b', ... 'XMinorTick','on', 'YMinorTick','on', 'TickDir','out', 'TickLength',[.005,.001]);truncAxis('X',[4, 4.5], 'Y',[2, 3], 'XResize','on', 'YResize','on')legendDemo 2% Generate sample dataData = [randi([20, 35], [5, 1]), randi([160, 190], [5, 1])];err = rand([5, 2]) .* 5;hold onbarHdl = bar(Data, 'BarWidth', 1, 'LineWidth',1);% Customize bar colors and transparencybarHdl(1).FaceColor = [153, 153, 253] ./ 255;barHdl(2).FaceColor = [255, 153, 154] ./ 255;barHdl(1).FaceAlpha = 0.9;barHdl(2).FaceAlpha = 0.9;% Render and customize error barserrorbar(barHdl(1).XEndPoints, Data(:, 1), err(:, 1), ... 'LineStyle', 'none', 'Color', 'k', 'LineWidth', 1);errorbar(barHdl(2).XEndPoints, Data(:, 2), err(:, 2), ... 'LineStyle', 'none', 'Color', 'k', 'LineWidth', 1);% Axes styling and label customizationax = gca;ax.YLim = [0, 200];ax.LineWidth = 1;ax.TickLength = [0.005, 0.001];ax.Box = 'on';ax.FontSize = 13;ax.XTick = 1:5;ax.XTickLabel = {'A', 'B', 'C', 'D', 'E'};axMat = truncAxis('Y', [50, 155]);axMat(1).Children(end).BaseLine.Color = 'none';% Add legendlegend({'AAAAA', 'BBBBB'}, 'FontSize', 13);
Engineering with Agentic AI: Using Skills to Improve Your Agent
#YouTube
via MATLAB@YouTube (author: MATLAB)
#YouTube
via MATLAB@YouTube (author: MATLAB)
YouTube
Engineering with Agentic AI: Using Skills to Improve Your Agent
AI agents are already remarkably good at writing code, but engineering requires more than code generation. It requires domain expertise, established workflows, validation practices, and lessons learned from experienced engineers.
Learn how to use skill files…
Learn how to use skill files…
📡 MATLAB Central - File Exchange - rating:5.0 | CATT2Matlab
More info in GitHub, clic on 'Learn more'.I'm developing the information, sorry, soon it will be more complete.Work in Windows and OSX. Screenshoots in GitHub.
More info in GitHub, clic on 'Learn more'.I'm developing the information, sorry, soon it will be more complete.Work in Windows and OSX. Screenshoots in GitHub.
JOSS:Macapype: An open multi-software framework for non-human primate brain anatomical MRI processing
Journal of Open Source Software
Macapype: An open multi-software framework for non-human primate brain anatomical MRI processing
Meunier et al., (2026). Macapype: An open multi-software framework for non-human primate brain anatomical MRI processing. Journal of Open Source Software, 11(125), 10203, https://doi.org/10.21105/joss.10203
📡 MATLAB Central - File Exchange - rating:4.5 | Deep Learning Tutorial Series
The code provides hands-on examples to implement convolutional neural networks (CNNs) for object recognition. The three demos have associated instructional videos that will allow for a complete tutorial experience to understand and implement deep learning techniques. The demos include:- Training a neural network from scratch- Using a pre-trained model (transfer learning)- Using a neural network as a feature extractor The use of a GPU and Parallel Computing Toolbox™ is recommended when running the examples. Demo 3 requires Statistics and Machine Learning Toolbox™ in addition to the required products below.
The code provides hands-on examples to implement convolutional neural networks (CNNs) for object recognition. The three demos have associated instructional videos that will allow for a complete tutorial experience to understand and implement deep learning techniques. The demos include:- Training a neural network from scratch- Using a pre-trained model (transfer learning)- Using a neural network as a feature extractor The use of a GPU and Parallel Computing Toolbox™ is recommended when running the examples. Demo 3 requires Statistics and Machine Learning Toolbox™ in addition to the required products below.
📡 MATLAB Central - File Exchange - rating:5.0 | dec2hex_ex
Matlab's dec2hex converts a vector of decimals into a charachter array - which is cumbersom to manipulatedec2hex_ex gives a solution for this...while... out = dec2hex([1 10 20]) out = 3×2 char array '01' '0A' '14' Syntax: [out,outCell] = dec2hex_ex(dec_vector,numDigits,addHexPrefix) Inputs: dec_vector: hold 1 or more decimals numDigits : optional, integer, can be given as empty braces ([]) addHexPrefix: optional, default = false, if true: adds '0x' so output could be sent to 'eval' function Outputs: out : The trivial output as char array outCell : Cell arrayoutput Examples: out = dec2hex_ex([1 10 20]) % out = '[1,A,14]' out = dec2hex_ex([1 10 20],3) % out = '[001, 00A, 014]' out = dec2hex_ex([1 10 20],[], 1) % out = '[0x1,0xA,0x14]' [out, outCell] = dec2hex_ex([1 10 20]) % outCell = {'1','A','14'} [out, outCell] = dec2hex_ex([1 10 20],[], 1) % outCell = {'0x1','0xA','0x14'} [out, outCell] = dec2hex_ex([1 10 20],4 , 1) % out = '[0x0001, 0x000A, 0x0014]'
Matlab's dec2hex converts a vector of decimals into a charachter array - which is cumbersom to manipulatedec2hex_ex gives a solution for this...while... out = dec2hex([1 10 20]) out = 3×2 char array '01' '0A' '14' Syntax: [out,outCell] = dec2hex_ex(dec_vector,numDigits,addHexPrefix) Inputs: dec_vector: hold 1 or more decimals numDigits : optional, integer, can be given as empty braces ([]) addHexPrefix: optional, default = false, if true: adds '0x' so output could be sent to 'eval' function Outputs: out : The trivial output as char array outCell : Cell arrayoutput Examples: out = dec2hex_ex([1 10 20]) % out = '[1,A,14]' out = dec2hex_ex([1 10 20],3) % out = '[001, 00A, 014]' out = dec2hex_ex([1 10 20],[], 1) % out = '[0x1,0xA,0x14]' [out, outCell] = dec2hex_ex([1 10 20]) % outCell = {'1','A','14'} [out, outCell] = dec2hex_ex([1 10 20],[], 1) % outCell = {'0x1','0xA','0x14'} [out, outCell] = dec2hex_ex([1 10 20],4 , 1) % out = '[0x0001, 0x000A, 0x0014]'
📡 MATLAB Central - File Exchange - rating:5.0 | Systems-Level Microgrid Simulation from One-Line Diagram
Simscape Power Systems can be used to schematically represent a one-line microgrid diagram using blocks that represent different distributed energy resources (DERs). The DERs in this example include renewables, such as solar, a diesel GenSet, and an energy storage system (ESS). Using the simple microgrid, you see how desktop simulation can be used to subject the distribution system with residential load changes or unintentional islanding of the microgrid. The included slides detail other common workflows for systems-level microgrid simulation. Using Simulink Real-time, this simple microgrid can quickly be migrated to a real-time machine for hardware-in-the-loop testing.
Simscape Power Systems can be used to schematically represent a one-line microgrid diagram using blocks that represent different distributed energy resources (DERs). The DERs in this example include renewables, such as solar, a diesel GenSet, and an energy storage system (ESS). Using the simple microgrid, you see how desktop simulation can be used to subject the distribution system with residential load changes or unintentional islanding of the microgrid. The included slides detail other common workflows for systems-level microgrid simulation. Using Simulink Real-time, this simple microgrid can quickly be migrated to a real-time machine for hardware-in-the-loop testing.
📡 MATLAB Central - File Exchange - rating:5.0 | Natural-Order Row Sort
SummaryNatural order sort the rows of a string/cell/categorical/table array. Sorts the text by character code taking into account the values of any number substrings. Compare for example:>> X = {'x2','10';'x10','0';'x1','0';'x2','2'};>> sortrows(X) % Wrong numeric orderans = 'x1' '0' 'x10' '0' 'x2' '10' 'x2' '2'>> natsortrows(X) % Correct numeric orderans = 'x1' '0' 'x2' '2' 'x2' '10' 'x10' '0'By default NATSORTROWS interprets all consecutive digits as integer numbers, the number substring recognition can be specified using a regular expression: see NATSORT for details.File DependencyThe natural-order sort is provided by the function NATSORT (File Exchange 34464). All of NATSORT's optional inputs are supported by NATSORTROWS.Examples>> A = {'B','2','X';'A','100','X';'B','10','X';'A','2','Y';'A','20','X'};>> sortrows(A) % SORTROWS for comparison.ans = 'A' '100' 'X' 'A' '2' 'Y' 'A' '20' 'X' 'B' '10' 'X' 'B' '2' 'X'>> natsortrows(A)ans = 'A' '2' 'Y' 'A' '20' 'X' 'A' '100' 'X' 'B' '2' 'X' 'B' '10' 'X'>> natsortrows(A,[],'descend')ans = 'B' '10' 'X' 'B' '2' 'X' 'A' '100' 'X' 'A' '20' 'X' 'A' '2' 'Y'>> sortrows(A,[2,-3]) % SORTROWS for comparison.ans = 'B' '10' 'X' 'A' '100' 'X' 'A' '2' 'Y' 'B' '2' 'X' 'A' '20' 'X'>> natsortrows(A,[],[2,-3])ans = 'A' '2' 'Y' 'B' '2' 'X' 'B' '10' 'X' 'A' '20' 'X' 'A' '100' 'X'>> natsortrows(A,[],[false,true,true],{'ascend','descend'})ans = 'A' '2' 'Y' 'B' '2' 'X' 'B' '10' 'X' 'A' '20' 'X' 'A' '100' 'X'>> natsortrows(A,[],{'ignore','ascend','descend'})ans = 'A' '2' 'Y' 'B' '2' 'X' 'B' '10' 'X' 'A' '20' 'X' 'A' '100' 'X'T = cell2table(A);natsortrows(T,[], [2,-3]) % TABLEans = A1 A2 A3 ___ _____ ___ 'A' '2' 'Y' 'B' '2' 'X' 'B' '10' 'X' 'A' '20' 'X' 'A' '100' 'X'natsortrows(T,[], {'A2','A3'},{'ascend','descend'}) % TABLEans = A1 A2 A3 ___ _____ ___ 'A' '2' 'Y' 'B' '2' 'X' 'B' '10' 'X' 'A' '20' 'X' 'A' '100' 'X'>> B = {'ABCD';'3e45';'67.8';'+Inf';'-12';'+9';'NaN'};>> sortrows(B) % SORTROWS for comparison.ans = '+9' '+Inf' '-12' '3e45' '67.8' 'ABCD' 'NaN'>> natsortrows(B,'[-+]?(NaN|Inf|\d+\.?\d*(E[-+]?\d+)?)')ans = '-12' '+9' '67.8' '3e45' '+Inf' 'NaN' 'ABCD'>> C = {'A2', 2; 'A10', 1; 'A2', 1}; % Scalar numerics in a column:>> natsortrows(C,[],'sortnum')ans = 'A2' [1] 'A2' [2] 'A10' [1]>> natsortrows(C,[],'sortnum',{'ascend','descend'})ans = 'A2' [2] 'A2' [1] 'A10' [1]See AlsoTo sort text into the order of arbitrary/custom text sequences (e.g. alphabets) use ARBSORT:https://www.mathworks.com/matlabcentral/fileexchange/132263-custom-list-arbitrary-sequence-sortTo sort the elements of a string/cell array use NATSORT: http://www.mathworks.com/matlabcentral/fileexchange/34464-customizable-natural-order-sortTo sort file-names or folder-names use NATSORTFILES: http://www.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sortGitHub collection of all of these functions:https://github.com/DrosteEffect/NaturalSortOrder
SummaryNatural order sort the rows of a string/cell/categorical/table array. Sorts the text by character code taking into account the values of any number substrings. Compare for example:>> X = {'x2','10';'x10','0';'x1','0';'x2','2'};>> sortrows(X) % Wrong numeric orderans = 'x1' '0' 'x10' '0' 'x2' '10' 'x2' '2'>> natsortrows(X) % Correct numeric orderans = 'x1' '0' 'x2' '2' 'x2' '10' 'x10' '0'By default NATSORTROWS interprets all consecutive digits as integer numbers, the number substring recognition can be specified using a regular expression: see NATSORT for details.File DependencyThe natural-order sort is provided by the function NATSORT (File Exchange 34464). All of NATSORT's optional inputs are supported by NATSORTROWS.Examples>> A = {'B','2','X';'A','100','X';'B','10','X';'A','2','Y';'A','20','X'};>> sortrows(A) % SORTROWS for comparison.ans = 'A' '100' 'X' 'A' '2' 'Y' 'A' '20' 'X' 'B' '10' 'X' 'B' '2' 'X'>> natsortrows(A)ans = 'A' '2' 'Y' 'A' '20' 'X' 'A' '100' 'X' 'B' '2' 'X' 'B' '10' 'X'>> natsortrows(A,[],'descend')ans = 'B' '10' 'X' 'B' '2' 'X' 'A' '100' 'X' 'A' '20' 'X' 'A' '2' 'Y'>> sortrows(A,[2,-3]) % SORTROWS for comparison.ans = 'B' '10' 'X' 'A' '100' 'X' 'A' '2' 'Y' 'B' '2' 'X' 'A' '20' 'X'>> natsortrows(A,[],[2,-3])ans = 'A' '2' 'Y' 'B' '2' 'X' 'B' '10' 'X' 'A' '20' 'X' 'A' '100' 'X'>> natsortrows(A,[],[false,true,true],{'ascend','descend'})ans = 'A' '2' 'Y' 'B' '2' 'X' 'B' '10' 'X' 'A' '20' 'X' 'A' '100' 'X'>> natsortrows(A,[],{'ignore','ascend','descend'})ans = 'A' '2' 'Y' 'B' '2' 'X' 'B' '10' 'X' 'A' '20' 'X' 'A' '100' 'X'T = cell2table(A);natsortrows(T,[], [2,-3]) % TABLEans = A1 A2 A3 ___ _____ ___ 'A' '2' 'Y' 'B' '2' 'X' 'B' '10' 'X' 'A' '20' 'X' 'A' '100' 'X'natsortrows(T,[], {'A2','A3'},{'ascend','descend'}) % TABLEans = A1 A2 A3 ___ _____ ___ 'A' '2' 'Y' 'B' '2' 'X' 'B' '10' 'X' 'A' '20' 'X' 'A' '100' 'X'>> B = {'ABCD';'3e45';'67.8';'+Inf';'-12';'+9';'NaN'};>> sortrows(B) % SORTROWS for comparison.ans = '+9' '+Inf' '-12' '3e45' '67.8' 'ABCD' 'NaN'>> natsortrows(B,'[-+]?(NaN|Inf|\d+\.?\d*(E[-+]?\d+)?)')ans = '-12' '+9' '67.8' '3e45' '+Inf' 'NaN' 'ABCD'>> C = {'A2', 2; 'A10', 1; 'A2', 1}; % Scalar numerics in a column:>> natsortrows(C,[],'sortnum')ans = 'A2' [1] 'A2' [2] 'A10' [1]>> natsortrows(C,[],'sortnum',{'ascend','descend'})ans = 'A2' [2] 'A2' [1] 'A10' [1]See AlsoTo sort text into the order of arbitrary/custom text sequences (e.g. alphabets) use ARBSORT:https://www.mathworks.com/matlabcentral/fileexchange/132263-custom-list-arbitrary-sequence-sortTo sort the elements of a string/cell array use NATSORT: http://www.mathworks.com/matlabcentral/fileexchange/34464-customizable-natural-order-sortTo sort file-names or folder-names use NATSORTFILES: http://www.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sortGitHub collection of all of these functions:https://github.com/DrosteEffect/NaturalSortOrder
📡 MATLAB Central - File Exchange - rating:5.0 | Natural-Order Filename Sort
SummaryNatural order sort the text in a string/cell/structure array. Sorts the text by character code taking into account the values of any number substrings. Compare for example:>> A = {'a2.txt', 'a10.txt', 'a1.txt'};>> sort(A)ans = 'a1.txt' 'a10.txt' 'a2.txt'>> natsortfiles(A)ans = 'a1.txt' 'a2.txt' 'a10.txt'By default NATSORTFILES interprets all consecutive digits as integer numbers, the number substring recognition can be specified using a regular expression: see NATSORT for details.NATSORTFILES does not perform a naive natural-order sort, but sorts the filenames and file extensions separately to ensure a dictionary sort, where shorter filenames always sort before longer ones. Likewise filepaths are split at each file-separator character, and each level of the file hierarchy is sorted separately.Example with DIR()P = 'C:\SomeDir\SubDir';S = dir(fullfile(P,'*.txt'));S = natsortfiles(S);for k = 1:numel(S) F = fullfile(P,S(k).name)endFile DependencyThe natural-order sort is provided by the function NATSORT (File Exchange 34464). All of NATSORT's optional inputs are supported by NATSORTFILES.Examples>> A = {'a2.txt', 'a10.txt', 'a1.txt'}>> sort(A)ans = 'a1.txt' 'a10.txt' 'a2.txt'>> natsortfiles(A)ans = 'a1.txt' 'a2.txt' 'a10.txt'>> B = {'test2.m'; 'test10-old.m'; 'test.m'; 'test10.m'; 'test1.m'};>> sort(B) % Wrong number order:ans = 'test.m' 'test1.m' 'test10-old.m' 'test10.m' 'test2.m'>> natsortfiles(B) % Shorter names before longer:ans = 'test.m' 'test1.m' 'test2.m' 'test10.m' 'test10-old.m'%% Directory Names:>> C = {'A2-old\test.m';'A10\test.m';'A2\test.m';'A1\test.m';'A1-archive.zip'};>> sort(C) % Wrong number order, and '-' sorts before '\':ans = 'A1-archive.zip' 'A10\test.m' 'A1\test.m' 'A2-old\test.m' 'A2\test.m'>> natsortfiles(C) % Shorter names before longer:ans = 'A1\test.m' 'A1-archive.zip' 'A2\test.m' 'A2-old\test.m' 'A10\test.m'>> D = {'A1\B', 'A+/B', 'A/B1', 'A=/B', 'A\B0'};>> sort(D)ans = 'A+/B' 'A/B1' 'A1\B' 'A=/B' 'A\B0'>> natsortfiles(D)ans = 'A\B0' 'A/B1' 'A1\B' 'A+/B' 'A=/B'>> F = {'test_new.m'; 'test-old.m'; 'test.m'};>> sort(F) % Note '-' sorts before '.':ans = 'test-old.m' 'test.m' 'test_new.m'>> natsortfiles(F) % Shorter names before longer:ans = 'test.m' 'test-old.m' 'test_new.m'See AlsoTo sort text into the order of arbitrary/custom text sequences (e.g. alphabets) use ARBSORT:https://www.mathworks.com/matlabcentral/fileexchange/132263-custom-list-arbitrary-sequence-sortTo sort the elements of a string/cell array use NATSORT: http://www.mathworks.com/matlabcentral/fileexchange/34464-customizable-natural-order-sortTo sort the rows of a string/cell array use NATSORTROWS: http://www.mathworks.com/matlabcentral/fileexchange/47433-natural-order-row-sortGitHub collection of all of these functions:https://github.com/DrosteEffect/NaturalSortOrder
SummaryNatural order sort the text in a string/cell/structure array. Sorts the text by character code taking into account the values of any number substrings. Compare for example:>> A = {'a2.txt', 'a10.txt', 'a1.txt'};>> sort(A)ans = 'a1.txt' 'a10.txt' 'a2.txt'>> natsortfiles(A)ans = 'a1.txt' 'a2.txt' 'a10.txt'By default NATSORTFILES interprets all consecutive digits as integer numbers, the number substring recognition can be specified using a regular expression: see NATSORT for details.NATSORTFILES does not perform a naive natural-order sort, but sorts the filenames and file extensions separately to ensure a dictionary sort, where shorter filenames always sort before longer ones. Likewise filepaths are split at each file-separator character, and each level of the file hierarchy is sorted separately.Example with DIR()P = 'C:\SomeDir\SubDir';S = dir(fullfile(P,'*.txt'));S = natsortfiles(S);for k = 1:numel(S) F = fullfile(P,S(k).name)endFile DependencyThe natural-order sort is provided by the function NATSORT (File Exchange 34464). All of NATSORT's optional inputs are supported by NATSORTFILES.Examples>> A = {'a2.txt', 'a10.txt', 'a1.txt'}>> sort(A)ans = 'a1.txt' 'a10.txt' 'a2.txt'>> natsortfiles(A)ans = 'a1.txt' 'a2.txt' 'a10.txt'>> B = {'test2.m'; 'test10-old.m'; 'test.m'; 'test10.m'; 'test1.m'};>> sort(B) % Wrong number order:ans = 'test.m' 'test1.m' 'test10-old.m' 'test10.m' 'test2.m'>> natsortfiles(B) % Shorter names before longer:ans = 'test.m' 'test1.m' 'test2.m' 'test10.m' 'test10-old.m'%% Directory Names:>> C = {'A2-old\test.m';'A10\test.m';'A2\test.m';'A1\test.m';'A1-archive.zip'};>> sort(C) % Wrong number order, and '-' sorts before '\':ans = 'A1-archive.zip' 'A10\test.m' 'A1\test.m' 'A2-old\test.m' 'A2\test.m'>> natsortfiles(C) % Shorter names before longer:ans = 'A1\test.m' 'A1-archive.zip' 'A2\test.m' 'A2-old\test.m' 'A10\test.m'>> D = {'A1\B', 'A+/B', 'A/B1', 'A=/B', 'A\B0'};>> sort(D)ans = 'A+/B' 'A/B1' 'A1\B' 'A=/B' 'A\B0'>> natsortfiles(D)ans = 'A\B0' 'A/B1' 'A1\B' 'A+/B' 'A=/B'>> F = {'test_new.m'; 'test-old.m'; 'test.m'};>> sort(F) % Note '-' sorts before '.':ans = 'test-old.m' 'test.m' 'test_new.m'>> natsortfiles(F) % Shorter names before longer:ans = 'test.m' 'test-old.m' 'test_new.m'See AlsoTo sort text into the order of arbitrary/custom text sequences (e.g. alphabets) use ARBSORT:https://www.mathworks.com/matlabcentral/fileexchange/132263-custom-list-arbitrary-sequence-sortTo sort the elements of a string/cell array use NATSORT: http://www.mathworks.com/matlabcentral/fileexchange/34464-customizable-natural-order-sortTo sort the rows of a string/cell array use NATSORTROWS: http://www.mathworks.com/matlabcentral/fileexchange/47433-natural-order-row-sortGitHub collection of all of these functions:https://github.com/DrosteEffect/NaturalSortOrder
📡 MATLAB Central - File Exchange - rating:5.0 | Customizable Natural-Order Sort
SummaryNatural order sort the text in a string/cell/categorical array. Sorts the text by character code taking into account the values of any number substrings. Compare for example:X = {'a2', 'a10', 'a1'}; sort(X) ans = 'a1' 'a10' 'a2' natsort(X) ans = 'a1' 'a2' 'a10'By default NATSORT interprets all consecutive digits as integer numbers, the number substring recognition can be specified using a regular expression, allowing the number substrings to have: a +/- sign a decimal point and decimal fraction E-notation exponentdecimal, octal, hexadecimal or binary notation Inf or NaN values criteria supported by regular expressions: lookarounds, quantifiers, etc.And of course the sorting itself can also be controlled: ascending/descending sort directioncharacter case sensitivity/insensitivityrelative order of numbers vs. charactersrelative order of numbers vs NaNsExamples%% Multiple integers (e.g. release version numbers):>> A = {'v10.6', 'v9.10', 'v9.5', 'v10.10', 'v9.10.20', 'v9.10.8'};>> sort(A) % for comparison.ans = 'v10.10' 'v10.6' 'v9.10' 'v9.10.20' 'v9.10.8' 'v9.5'>> natsort(A)ans = 'v9.5' 'v9.10' 'v9.10.8' 'v9.10.20' 'v10.6' 'v10.10'%% Integer, decimal, NaN, or Inf numbers, possibly with +/- signs:>> B = {'test+NaN', 'test11.5', 'test-1.4', 'test', 'test-Inf', 'test+0.3'};>> sort(B) % for comparison.ans = 'test' 'test+0.3' 'test+NaN' 'test-1.4' 'test-Inf' 'test11.5'>> natsort(B, '[-+]?(NaN|Inf|\d+\.?\d*)')ans = 'test' 'test-Inf' 'test-1.4' 'test+0.3' 'test11.5' 'test+NaN'%% Integer or decimal numbers, possibly with an exponent:>> C = {'0.56e007', '', '43E-2', '10000', '9.8'};>> sort(C) % for comparison.ans = '' '0.56e007' '10000' '43E-2' '9.8'>> natsort(C, '\d+\.?\d*(E[-+]?\d+)?')ans = '' '43E-2' '9.8' '10000' '0.56e007'%% Hexadecimal numbers (with '0X' prefix):>> D = {'a0X7C4z', 'a0X5z', 'a0X18z', 'a0XFz'};>> sort(D) % for comparison.ans = 'a0X18z' 'a0X5z' 'a0X7C4z' 'a0XFz'>> natsort(D, '0X[0-9A-F]+', '%i')ans = 'a0X5z' 'a0XFz' 'a0X18z' 'a0X7C4z'%% Binary numbers:>> E = {'a11111000100z', 'a101z', 'a000000000011000z', 'a1111z'};>> sort(E) % for comparison.ans = 'a000000000011000z' 'a101z' 'a11111000100z' 'a1111z'>> natsort(E, '[01]+', '%b')ans = 'a101z' 'a1111z' 'a000000000011000z' 'a11111000100z'%% Case sensitivity:>> F = {'a2', 'A20', 'A1', 'a10', 'A2', 'a1'};>> natsort(F, [], 'ignorecase') % defaultans = 'A1' 'a1' 'a2' 'A2' 'a10' 'A20'>> natsort(F, [], 'matchcase')ans = 'A1' 'A2' 'A20' 'a1' 'a2' 'a10'%% Sort order:>> G = {'2', 'a', '', '3', 'B', '1'};>> natsort(G, [], 'ascend') % defaultans = '' '1' '2' '3' 'a' 'B'>> natsort(G, [], 'descend')ans = 'B' 'a' '3' '2' '1' ''>> natsort(G, [], 'num> natsort(G, [], 'char> natsort({'a18446744073709551615z', 'a18446744073709551614z'}, [], '%lu')ans = 'a18446744073709551614z' 'a18446744073709551615z'See AlsoTo sort text into the order of arbitrary/custom text sequences (e.g. alphabets) use ARBSORT:https://www.mathworks.com/matlabcentral/fileexchange/132263-custom-list-arbitrary-sequence-sortTo sort file-names or folder-names use NATSORTFILES:http://www.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sortTo sort the rows of a string/cell array use NATSORTROWS:http://www.mathworks.com/matlabcentral/fileexchange/47433-natural-order-row-sortGitHub collection of all of these functions:https://github.com/DrosteEffect/NaturalSortOrder
SummaryNatural order sort the text in a string/cell/categorical array. Sorts the text by character code taking into account the values of any number substrings. Compare for example:X = {'a2', 'a10', 'a1'}; sort(X) ans = 'a1' 'a10' 'a2' natsort(X) ans = 'a1' 'a2' 'a10'By default NATSORT interprets all consecutive digits as integer numbers, the number substring recognition can be specified using a regular expression, allowing the number substrings to have: a +/- sign a decimal point and decimal fraction E-notation exponentdecimal, octal, hexadecimal or binary notation Inf or NaN values criteria supported by regular expressions: lookarounds, quantifiers, etc.And of course the sorting itself can also be controlled: ascending/descending sort directioncharacter case sensitivity/insensitivityrelative order of numbers vs. charactersrelative order of numbers vs NaNsExamples%% Multiple integers (e.g. release version numbers):>> A = {'v10.6', 'v9.10', 'v9.5', 'v10.10', 'v9.10.20', 'v9.10.8'};>> sort(A) % for comparison.ans = 'v10.10' 'v10.6' 'v9.10' 'v9.10.20' 'v9.10.8' 'v9.5'>> natsort(A)ans = 'v9.5' 'v9.10' 'v9.10.8' 'v9.10.20' 'v10.6' 'v10.10'%% Integer, decimal, NaN, or Inf numbers, possibly with +/- signs:>> B = {'test+NaN', 'test11.5', 'test-1.4', 'test', 'test-Inf', 'test+0.3'};>> sort(B) % for comparison.ans = 'test' 'test+0.3' 'test+NaN' 'test-1.4' 'test-Inf' 'test11.5'>> natsort(B, '[-+]?(NaN|Inf|\d+\.?\d*)')ans = 'test' 'test-Inf' 'test-1.4' 'test+0.3' 'test11.5' 'test+NaN'%% Integer or decimal numbers, possibly with an exponent:>> C = {'0.56e007', '', '43E-2', '10000', '9.8'};>> sort(C) % for comparison.ans = '' '0.56e007' '10000' '43E-2' '9.8'>> natsort(C, '\d+\.?\d*(E[-+]?\d+)?')ans = '' '43E-2' '9.8' '10000' '0.56e007'%% Hexadecimal numbers (with '0X' prefix):>> D = {'a0X7C4z', 'a0X5z', 'a0X18z', 'a0XFz'};>> sort(D) % for comparison.ans = 'a0X18z' 'a0X5z' 'a0X7C4z' 'a0XFz'>> natsort(D, '0X[0-9A-F]+', '%i')ans = 'a0X5z' 'a0XFz' 'a0X18z' 'a0X7C4z'%% Binary numbers:>> E = {'a11111000100z', 'a101z', 'a000000000011000z', 'a1111z'};>> sort(E) % for comparison.ans = 'a000000000011000z' 'a101z' 'a11111000100z' 'a1111z'>> natsort(E, '[01]+', '%b')ans = 'a101z' 'a1111z' 'a000000000011000z' 'a11111000100z'%% Case sensitivity:>> F = {'a2', 'A20', 'A1', 'a10', 'A2', 'a1'};>> natsort(F, [], 'ignorecase') % defaultans = 'A1' 'a1' 'a2' 'A2' 'a10' 'A20'>> natsort(F, [], 'matchcase')ans = 'A1' 'A2' 'A20' 'a1' 'a2' 'a10'%% Sort order:>> G = {'2', 'a', '', '3', 'B', '1'};>> natsort(G, [], 'ascend') % defaultans = '' '1' '2' '3' 'a' 'B'>> natsort(G, [], 'descend')ans = 'B' 'a' '3' '2' '1' ''>> natsort(G, [], 'num> natsort(G, [], 'char> natsort({'a18446744073709551615z', 'a18446744073709551614z'}, [], '%lu')ans = 'a18446744073709551614z' 'a18446744073709551615z'See AlsoTo sort text into the order of arbitrary/custom text sequences (e.g. alphabets) use ARBSORT:https://www.mathworks.com/matlabcentral/fileexchange/132263-custom-list-arbitrary-sequence-sortTo sort file-names or folder-names use NATSORTFILES:http://www.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sortTo sort the rows of a string/cell array use NATSORTROWS:http://www.mathworks.com/matlabcentral/fileexchange/47433-natural-order-row-sortGitHub collection of all of these functions:https://github.com/DrosteEffect/NaturalSortOrder