MATLAB Answers

saving workspace of each pair of variable in a loop

22 views (last 30 days)
Samson on 24 Oct 2020
Commented: Samson on 26 Oct 2020
I help. I have a loop where I take each pair of variables and run. However, I want to save the workspace of each pair after each iterations. see example below:
iteration = 10
for ii = 1: length (X)
for jj = 1: length (Y)
display (['ii is', num2str (ii), 'and jj is', num2str (jj)])
%%% Function Call
let say X = 1 2 3
y = 5 6 7
I want to save the workspace for each pair. For instance, to save ii = 1 and jj = 5, etc
Samson on 26 Oct 2020
you want to save all variables in a mat file for each iteration? = yes. saving each pair of the iteration in a worspace. from the example of the data I gave for X and Y. I would love to see 9 workspaces

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 26 Oct 2020
for ii = 1:numel(X)
for jj = 1:numel(Y)
... your code
fnm = sprintf('workspace_%d_%d.mat',ii,jj);

More Answers (0)



Community Treasure Hunt

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

Start Hunting!

Translated by