loop save new name and save .mat

3 次查看(过去 30 天)
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 个评论
Jan
Jan 2017-1-24
编辑:Jan 2017-1-24
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.

请先登录,再进行评论。

回答(2 个)

Jan
Jan 2017-1-24
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 个评论
Jan
Jan 2017-1-25
编辑:Jan 2017-1-25
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.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2017-1-25
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 个评论
Walter Roberson
Walter Roberson 2017-1-25
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
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by