主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

copyFileFromStore

将文件从 FileStore 对象复制到本地文件系统

自 R2022a 起

说明

copyFileFromStore(store,keySet,fileSet) 将键 store 指定的文件从 keySet 复制到本地文件系统 fileSet

示例

示例

全部折叠

在进程工作单元的并行池上运行仿真并检索客户端上的文件存储。文件存储是一个带有关键文件条目的 FileStore 对象。使用 copyFileFromStore 函数根据相应键的指定从此对象复制文件。

下面的仿真找到随机矩阵的平均值和标准差,并将结果存储在 FileStore 对象中。

type workerStatsCode
function workerStatsCode(models)
% Get the FileStore of the current job
store = getCurrentFileStore;
for i = 1:numel(models)
    % Compute the average and standard deviation of random matrices
    A = rand(models(i));
    M = mean(A);
    S = std(A);
    % Save simulation results in temporary files
    sourceTempFile = strcat(tempname("C:\myTempFolder"),".mat");
    save(sourceTempFile,"M","S");
    % Copy files to FileStore object as key-file pairs
    key = strcat("result_",num2str(i));
    copyFileToStore(store,sourceTempFile,key);
end
end

启动一个进程工作单元的并行池。

pool = parpool('Processes');
Starting parallel pool (parpool) using the 'Processes' profile ...
Connected to the parallel pool (number of workers: 6).

获取该池的 FileStore

store = pool.FileStore;

在池上运行仿真。

models = [4,8,32,20];
future = parfeval(@workerStatsCode,0,models);
wait(future);

显示 FileStore 对象的键。

keys(store)
ans = 4×1 string
    "result_1"
    "result_2"
    "result_3"
    "result_4"

将文件从相应键 "result_1""result_2" 指定的文件存储复制到本地文件 "run_1.mat""run_2.mat"

copyFileFromStore(store,["result_1" "result_2"],["run_1.mat" "run_2.mat"])

显示存储在本地文件中的变量的所有信息。

whos -file 'run_1.mat'
  Name      Size            Bytes  Class     Attributes

  M         1x4                32  double              
  S         1x4                32  double              
whos -file 'run_2.mat'
  Name      Size            Bytes  Class     Attributes

  M         1x8                64  double              
  S         1x8                64  double              

输入参数

全部折叠

由 MATLAB 客户端和工作单元共享的文件存储,指定为 FileStore 对象。

要复制的键,指定为字符向量、字符串标量、字符串数组、或者字符向量或字符串的元胞数组。keySetfileSet 必须具有相同数量的元素。

示例: ["myDataKey" "myLogKey"]

本地文件,指定为字符向量、字符串标量、字符串数组、或者字符向量或字符串的元胞数组。keySetfileSet 必须具有相同数量的元素。

示例: ["/data/run.mat" "/tmp/run_log.txt"]

版本历史记录

在 R2022a 中推出