Clear Filters
Clear Filters

loop save new name and save .mat

3 views (last 30 days)
Adisorn Phanukthong
Adisorn Phanukthong on 24 Jan 2017
This is main function
function [] = READIMAGEFORAREA ()
srcFiles = dir('C:\Users\xzaa\Documents\MATLAB\bwwalk2\*.jpg'); % the folder in which ur images exists
j=1;
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\xzaa\Documents\MATLAB\bwwalk2\',srcFiles(i).name);
I = imread(filename);
imshow(I);
drawnow;
AREAPICTURE (I,j);
j=j+1;
end
end
and 2nd function
function [] = AREAPICTURE (BW,i)
BWAREA = bwarea(BW);
j=num2str(i);
save('AREA.mat',strcat('BWAREA00'),j);
end
I want to save in file .mat and save many object in .mat in code that error loop in program
this error Error in AREAPICTURE (line 4) save('AREA.mat',strcat('BWAREA00'),j);
Error in READIMAGEFORAREA (line 9) AREAPICTURE (I,j);
  1 Comment
Jan
Jan on 24 Jan 2017
Edited: Jan on 24 Jan 2017
Please read and apply: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup . Then edit the question and insert the complete error message: currently we can only see, where the problem occurres, but not which problem.

Sign in to comment.

Answers (2)

Jan
Jan on 24 Jan 2017
Your code:
function [] = AREAPICTURE (BW,i)
BWAREA = bwarea(BW);
j = num2str(i);
save('AREA.mat',strcat('BWAREA00'),j)
This is equivalent to the call (when i=7):
save AREA.mat BWAREA00 7
and tries to save the variables "BWAEREA00" and "7" to the file called "AREA.mat". Due to the lack of comment we have to guess the intention of this code. A bold guess:
function AREAPICTURE(BW, index) % Use "i" for the imaginary unit only
BWAREA = bwarea(BW);
save(sprintf('BWAREA%03d.mat', index), 'BWAREA')
  3 Comments
Jan
Jan on 25 Jan 2017
Edited: Jan on 25 Jan 2017
The message means, that you do not have write permissions in the current folder. Then add a folder using fullfile.
Please explain, if you want to save multiple files or 1 MAT file only.

Sign in to comment.


Walter Roberson
Walter Roberson on 25 Jan 2017
function AREAPICTURE(BW, index) % Use "i" for the imaginary unit only
BWAREA = bwarea(BW);
field = sprintf('BWAREA%d', index);
datastruct.(field) = BWAREA;
save('AREA.mat', '-struct', 'datastruct', '-append')
If you were to use a -v7.3 .mat file then you could handle this a bit more cleanly using matFile()
  5 Comments
Walter Roberson
Walter Roberson on 25 Jan 2017
Possibly the problem occurs while reading the 21st image. You should put in some debugging:
function [] = READIMAGEFORAREA ()
projectdir = 'C:\Users\xzaa\Documents\MATLAB\bwwalk2'
srcFiles = dir( fullfile(projectdir, '*.jpg') );
IGNORETHISVARIABLE = []; %the file needs to exist
save( 'AREA.mat', 'IGNORETHISVARIABLE');
for index = 1 : length(srcFiles)
filename = fullfile(projectdir, srcFiles(index).name );
fprintf('about to read image #%d: "%s"\n', index, filename);
I = imread(filename);
fprintf('image #%d read\n', index);
imshow(I);
drawnow;
AREAPICTURE(I, index);
end
function AREAPICTURE(BW, index)
BWAREA = bwarea(BW);
field = sprintf('BWAREA%d', index);
datastruct.(field) = BWAREA;
fprintf('about to save field %s\n', field);
save('AREA.mat', '-struct', 'datastruct', '-append')
fprintf('saved field %s\n', field);
Adisorn Phanukthong
Adisorn Phanukthong on 26 Jan 2017
Thank you first code run pass. promblem that about ram on my computer work single. I'm thank you so much. When I have problem. I'll say to you later.
Do you have Line ID or Social? I want contact to you
E-mail : xzaazakudo@gmail.com Line : xzaazakudo

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!