フィルターのクリア

loop save new name and save .mat

3 ビュー (過去 30 日間)
Adisorn Phanukthong
Adisorn Phanukthong 2017 年 1 月 24 日
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 Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by