How do i save a file into a folder in a different path?
Show older comments
I am coding a project that uses neural networks. my neural networks are saved into the same path as this piece of code. i want to save each segmented image in another file location, each with a different name.
%Open files
testfiledir = 'X:\eee_biophotonics1\Shared\SPOT dataset (Training data)\Testing Images\123 images on 123 network\OCT';
matfiles = dir(fullfile(testfiledir, '*.tif'));
nfiles = length(matfiles); %finds length of file
data = cell(nfiles);
for i = 1 : nfiles
fid = fopen( fullfile(testfiledir, matfiles(i).name) ); %retrieves specific file
load('net_123.mat'); % This loads the network back into MATLAB
result = semanticseg(fid,net_123); % This segments an image "I" using the network
filename='X:\eee_biophotonics1\Shared\SPOT dataset (Training data)\Testing Images\123 images on 123 network\nn segmented';
save(result,'%d',i,'-tif');
fclose(fid);
end
Accepted Answer
More Answers (1)
Dimitri MANKOV
on 1 Dec 2022
Edited: Dimitri MANKOV
on 1 Dec 2022
1 vote
Hi Rachel,
That should be fairly straightforward. You can create:
- a new directory each iteration of the 'for' loop, and save your file there, and/or
- a new file each iteration of the 'for' loop, and save it in a pre-defined directory.
Here is an example in which I generate a new variable 'a' every iteration, and save it in a new folder that I create in the current directory each time (using a different file name every time as well):
for idx = 1:10
a = rand(5);
mydirname = [cd,'\TMP',num2str(idx)];
myfilename = [mydirname,'\file',num2str(idx),'.mat'];
mkdir(mydirname)
save(myfilename,'a')
end
I hope this is helpful!
Dimitri
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!