필터 지우기
필터 지우기

loop save new name and save .mat

조회 수: 3 (최근 30일)
Adisorn Phanukthong
Adisorn Phanukthong 2017년 1월 24일
댓글: Adisorn Phanukthong 2017년 1월 26일
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
Adisorn Phanukthong
Adisorn Phanukthong 2017년 1월 25일
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
Adisorn Phanukthong 2017년 1월 26일
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