isShuffleable
说明
如果数据存储 ds
可乱序,则 tf = isShuffleable(
返回逻辑值 ds
)1
(true
)。否则,结果为逻辑值 0
(false
)。
如果所有基础数据存储均可乱序,则
TransformedDatastore
可乱序。如果所有基础数据存储都具有
subset
方法,或都是具有subset
方法的数据存储的变换/组合,则CombinedDatastore
和SequentialDatastore
可乱序。如果自定义数据存储类是
matlab.io.datastore.Shuffleable
的子类,则它们可乱序。
您可以对可乱序的数据存储使用 shuffle
函数来随机化文件排序,同时保留不同数据存储中文件的行关联。
示例
测试数据存储是否可乱序
创建一个 ImageDatastore
,然后编写一条仅在数据存储可乱序时才对其进行乱序的 if/else
语句。
imageFiles = {'street1.jpg','street2.jpg','peppers.png','corn.tif'}; imds = imageDatastore(imageFiles); if isShuffleable(imds) newds = shuffle(imds); disp('Shuffling successful.') else disp('Datastore is not shuffleable.') end
Shuffling successful.
现在创建一个 CombinedDatastore
对象,它包含 imds
的两个副本。使用相同的 if/else
测试来对该数据存储进行乱序处理。
cds = combine(imds,imds); if isShuffleable(cds) newds = shuffle(cds); disp('Shuffling successful.') else disp('Datastore is not shuffleable.') end
Shuffling successful.
在本例中,合并数据存储 cds
可乱序,因为基础 ImageDatastore
对象具有 subset
方法。
创建另一个 CombinedDatastore
对象,但这次基于 TabularTextDatastore
对象构造该对象。在本例中,合并数据存储不可乱序,因为基础 TabularTextDatastore
对象没有 subset
方法。
ttds = tabularTextDatastore('outages.csv'); cds = combine(ttds,ttds); if isShuffleable(cds) newds = shuffle(cds); disp('Shuffling successful.') else disp('Datastore is not shuffleable.') end
Datastore is not shuffleable.
输入参数
ds
— 输入数据存储
数据存储
输入数据存储。您可以将下列数据存储用作输入:
MATLAB® 数据存储 - 使用 MATLAB
datastore
函数创建的数据存储。例如,使用ImageDatastore
为图像集合创建一个数据存储。有关完整的数据存储列表,请参阅Select Datastore for File Format or Application。自定义数据存储 - 使用自定义数据存储框架创建的数据存储。基于
matlab.io.Datastore
子类化的任何数据存储都支持isShuffleable
函数。有关详细信息,请参阅Develop Custom Datastore。
扩展功能
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
用法说明和限制:
在基于线程的环境中,您只能对以下数据存储使用
isShuffleable
:ImageDatastore
对象使用
combine
或transform
从ImageDatastore
对象创建的CombinedDatastore
、SequentialDatastore
或TransformedDatastore
对象
如果您有 Parallel Computing Toolbox™,则可以对其他数据存储使用
isShuffleable
。为此,请使用基于进程的并行池运行该函数,而不是使用backgroundPool
或ThreadPool
(使用ProcessPool
或ClusterPool
)。
版本历史记录
在 R2020a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)