Sam
Sam

Reputation: 487

saving data from workspace to different dirrectory in matlab

I have a loop which my main script run through that. I wounder to save some of my variables in different directory every time that my loop is running. I have used following script but its not working:

for i=1:size(whisk, 1);

    my codes is here and it creates variables in my workspace  like [format, measurements].
    the rest is what I wote to save this variables:
    mkdir('C:\videos\results\', num2str(i));
    dumvar=0; % As matlab has problem with data>2GB, then I use this 2 line code for saving
    save('measurenments','dumvar','-v7.3');
    save(fullfile('C:\videos\results\', num2str(i),'measurenments'));
    clear all;
    close all;
end

but Unfortunately its not work!!!!!!!!!!! Any help would be appreciated. Sam

Upvotes: 0

Views: 182

Answers (1)

patrik
patrik

Reputation: 4558

Except that measurenments is wrongly spelled (correct spelling is measurements), there is not so strange that it does not work. The first call to save, saves the variable dumvar in the current folder, with the format v7.3. The second call to save, saves the whole workspace as a file fullfile('C:\videos\results\', num2str(i),'measurenments'). Try this,

save(fullfile('C:\videos\results\', num2str(i),'measurenments'),'dumvar','-v7.3');

However it seems as the folder fullfile('C:\videos\results\', num2str(i),'measurenments') does not exist since you only create the folder mkdir('C:\videos\results\', num2str(i)) . Then matlab cannot save anything there. Try either to save as fullfile('C:\videos\results\', [num2str(i),'measurenments']) or create the directory mkdir('C:\videos\results\', [num2str(i),'\','measurenments']); `

Upvotes: 1

Related Questions