Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Save matrix in a loop
Replies: 1   Last Post: Jul 15, 2013 10:38 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Curious

Posts: 1,982
Registered: 12/6/04
Re: Save matrix in a loop
Posted: Jul 15, 2013 10:38 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"shazwani kamarudin" wrote in message <ks0aje$o7e$1@newscl01ah.mathworks.com>...
> 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


% I'm not sure what"matrix data" you are trying to save,
% but if the rest of your code works,
% couldn't you just add something like:

matfile = sprintf('%d.mat', i);
matfilename = fullfile(pathname, matfile);
save(matfilename);

% to your existing for loop?

% You might also take a look at Q3.1 & 3.10
% of the MATLAB FAQ at:

http://matlab.wikia.com/wiki/FAQ

% Specifically:

<<http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F>>

<<http://matlab.wikia.com/wiki/FAQ#How_do_I_dynamically_generate_a_filename_for_SAVE.3F>>



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.