File Exchange

image thumbnail

parsave

version 1.2.0.0 (1.06 KB) by Philip
This function allows you to save variables inside a parfor loop.

3 Downloads

Updated 16 Mar 2011

View License

Unlike MATLAB's solution, the variables are saved with their variable names'. You must call this function for each variable you want to save, but the function will not overwrite previous mat files.

function parsave(fname,data)

var_name=genvarname(inputname(2));
eval([var_name '=data'])

try
save(fname,var_name,'-append')
catch
save(fname,var_name)
end

Comments and Ratings (7)

Philip

@Chris: Nevermind, I see your error when called inside a parfor loop. I'm not sure how to update the code, it seems Mathworks has closed this loophole.

Chris

Whe I use your function in R2016a it results in a "Transparency violation error"; line 3 seems to cause the error. Any known workaround?

Hariprasad

sorry, I got it. I was sending the data part for parsave in quotes. Sorry Again

Hariprasad

I tried using this function where in I want to save the data in a variable Dataset_info but the variable which gets saved in the matfile is named 'x'.
What I'm trying is, inside the parfor loop I'm using parsave([path,'Dataset_info.mat'],Dataset_info);
Is this correct? I want to save the Matfile as Dataset_info.mat with the data variable stored as Dataset_info as well. It contains cell array data.

Pearl

Philip

What does this have to do with saving variables in a parfor loop?

Updates

1.2.0.0

Edited description.

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux