Why Matlab throw an "Unrecognized function or variable 'splitEachLabel" error?

I'm making a custom loop for training a neural network. When I was trying to use the "splitEachLabel" function for splitting the datastore, I got an error:
[imdsTrain, imdsVal] = splitEachLabel(imds,0.8,'randomize');
"Unrecognized function or variable 'splitEachLabel'."
I checked if I have toolboxes that are needed for the project and if this function exists .
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 25.2.0.2998904 (R2025b)
Operating System: Microsoft Windows 10 Home Version 10.0 (Build 19045)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 25.2 (R2025b)
Simulink Version 25.2 (R2025b)
Computer Vision Toolbox Version 25.2 (R2025b)
Control System Toolbox Version 25.2 (R2025b)
Deep Learning HDL Toolbox Version 25.2 (R2025b)
Deep Learning Toolbox Version 25.2 (R2025b)
Embedded Coder Version 25.2 (R2025b)
Image Processing Toolbox Version 25.2 (R2025b)
MATLAB Coder Version 25.2 (R2025b)
Parallel Computing Toolbox Version 25.2 (R2025b)
Statistics and Machine Learning Toolbox Version 25.2 (R2025b)
Symbolic Math Toolbox Version 25.2 (R2025b)
>> which splitEachLabel -all
'splitEachLabel' not found.
I also run in command line:
run restoredefaultpath; rehash toolboxcache
because that was suggested by Copilot. That didn't help.

2 个评论

My guess is that you need the Audio Toolbox to use the function:
which splitEachLabel
/MATLAB/toolbox/audio/audio/@audioDatastore/splitEachLabel.m % audioDatastore method
[~, products] = matlab.codetools.requiredFilesAndProducts('splitEachLabel.m')
products = 1×2 struct array with fields:
Name Version ProductNumber Certain
products.Name
ans = 'MATLAB'
ans = 'Audio Toolbox'
If you are using an ImageDatastore object for the first parameter, you should be able to use the "splitEachLabel" function regardless of Audio Toolbox because it is a built-in object function.
May I ask you if you're unable to run this example also?
imds = imageDatastore(fullfile(matlabroot, 'toolbox', 'matlab', {'demos'}),...
'LabelSource', 'foldernames', 'FileExtensions', {'.jpg', '.png', '.tif'});
imds.Labels
[imds60, imds40] = splitEachLabel(imds,0.6,'Include','demos')

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Image Data Workflows 的更多信息

产品

版本

R2025b

提问:

2026-1-21

评论:

2026-1-26

Community Treasure Hunt

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

Start Hunting!

Translated by