Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Save matrix in a loop
Date: Mon, 15 Jul 2013 08:07:10 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 18
Message-ID: <ks0aje$o7e$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1373875630 24814 172.30.248.48 (15 Jul 2013 08:07:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 15 Jul 2013 08:07:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 4253316
Xref: news.mathworks.com comp.soft-sys.matlab:799312

hello~

this is my code to segment all images in testing folder..the problem is,i want to save each matrix data in different .mat file using a loop..i dont know how to do it

clear all
srcFiles = dir('\MSc AIA\amazon images\1-1000\testing\*.jpg'); 
for i = 1 : length(srcFiles)
    
filename = strcat('\MSc AIA\amazon images\1-1000\testing\',srcFiles(i).name);
I = imread(filename); 
level = graythresh(I);
BW = im2bw(I,level);
pathname = '\MSc AIA\amazon images\1-1000\testing\segmented';
segment = sprintf('%d.bmp', i);
fullfilename = fullfile(pathname, segment);
imwrite(BW, fullfilename);

end