필터 지우기
필터 지우기

What is wrong with the code?

조회 수: 2 (최근 30일)
sidra
sidra 2013년 11월 7일
댓글: sidra 2013년 11월 13일
I have created an imagearray consisting of 434 images, then extracted features from this imagearray using a function, now i want to store these features in a file in append mode.But when i do the last bit that is storing the features in a file i get an error.
for i=1:length(imagefile)
%images store in a variable imgarray
%Extracting features
fea=waveletfea(imgarray);
%Storing features
save('feature.mat','fea','-append');
end
error:
Unable to write MAT file
file may be corrupt
error in save('feature.mat','fea','append');
Any suggestions would be very helpful.Thanks in advance.

채택된 답변

Image Analyst
Image Analyst 2013년 11월 11일
I'd store the results into a cell array or regular array and then just write out the array with one call to save() after the loop exits.
for k = 1 : n
% Code to read in imgarray, then...
fea{k} = waveletfea(imgarray);
end
folder = pwd;
baseFileName = 'feature.mat';
fullFileName = fullfile(folder, baseFileName);
save(fullFileName,'fea');
but first you have to make sure you have write access to the folder.
  댓글 수: 2
sidra
sidra 2013년 11월 12일
Walter and Image Analyst thank you so much.
@Image Analyst: I will try this approach and get back to you with the results. Thanks again.
sidra
sidra 2013년 11월 13일
Image Analyst your code worked out perfectly. Thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

ES
ES 2013년 11월 7일
편집: ES 2013년 11월 7일
Is it not
save(filename,variables,'-append')
with a '-append' instead of just 'append'?
  댓글 수: 1
sidra
sidra 2013년 11월 7일
I have used
save('feature.mat','fea','-append');
Sorry, typing error. Even though the format is right, i get the above said error.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2013년 11월 9일
Unless you use different variable names for each file, append mode is going to replace the variable when you eventually read the file in. There is no provided way in MATLAB to say "load the 5th instance of the variable fea", and no way to index after loading to indicate "the 5th instance of how it was saved".
save -append does not act to concatenate the new data on to the end of the existing variable to produce a larger array.
You want to be concatenating to the end of an existing variable in a .mat file, see the matfile class.
I do not know why you are getting the corruption you are getting, but if you were to be using a -v7 file and were to append enough data, then the file itself could end up over 2 Gb, which is the maximum file size supported in -v7 .
  댓글 수: 2
sidra
sidra 2013년 11월 10일
Walter but isn't 'append mode' the best to store features in such a case? Because of the following statement on help : " -append: Add new variables to those already stored in an existing MAT-file".
And if not, then please suggest another way of storing the features from different images into a file.
Thank you in advance.
Walter Roberson
Walter Roberson 2013년 11월 12일
The key is "append new variables". Not append to an existing variable.
If you want to append to an existing variable, see the matfile class.
Image Analyst's idea of storing into a cell array and writing it out at the end, is good for most situations.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by