필터 지우기
필터 지우기

Could anyone explain the code for me ?

조회 수: 7 (최근 30일)
tabw
tabw 2014년 8월 6일
편집: dpb 2014년 8월 7일
file_path = dir(''); fid = fopen(''); pattern_col = 0;
while ~feof(fid)
pattern_col = pattern_col + 1; %coloum increment is 1
exp = []; %initialize the sample data
area_sample = [];
angle_sample = [];
fcontent = fgetl(fid); %get pattern size
pattern_size = fcontent;
fcontent = fgetl(fid); %get time interval
pattern_hour = fcontent;
fcontent = fgetl(fid); %get file path
file_path_disp = fcontent;
file_path = dir(fcontent); %should be specific
file_num = size(file_path, 1);
Could anyone explain the code for me ? It can read a image file ? especially the beginning. file_path = dir(''); fid = fopen('');
Can you make up some example for me ? thanks
  댓글 수: 4
dpb
dpb 2014년 8월 6일
What's missing?
doc imread
for the function.
tabw
tabw 2014년 8월 7일
편집: tabw 2014년 8월 7일
IF the file is not in current directory
file_path = dir('C:\Users\user\Desktop'); % to Detect png file on Desktop
How to use fopen() to open series of file? say, the file are called text1.txt,text2.txt,text3.txt ...
Actaully,the code is like that
file_path = dir('');
fid = fopen('');
while ~feof(fid)
And I don't know what should I put inside the fopen

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

채택된 답변

dpb
dpb 2014년 8월 6일
...Can you make up some example...
See the FAQ
last example on subject.

추가 답변 (2개)

Image Analyst
Image Analyst 2014년 8월 6일
And fclose() is also missing. This will only read an image file if the image file was written out as ASCII text. Otherwise you should use fread() rather than fgetl() to get the pixels out. And that's only if it's some custom format that imread() doesn't know about.
  댓글 수: 3
dpb
dpb 2014년 8월 7일
Please don't make same comments more than once't--_*most*_ confusing about what is/isn't answered...
Image Analyst
Image Analyst 2014년 8월 7일
Don't use dir() in that case. Just say
folder = pwd; %'C:\Users\user\Desktop'
filePattern = sprintf('%s/*.PNG', folder) % Find PNG image files.
fileNames = dir(filePattern)
for k = 1 : length(fileNames)
thisBaseFileName = fileNames(k).name;
thisFullFileName = fullfile(folder, thisBaseFileName);
fprintf('Now processing %s...\n', thisFullFileName);
end

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


dpb
dpb 2014년 8월 7일
편집: dpb 2014년 8월 7일
...IF the file is not in current directory...
Then include it in the argument to dir, of course...
file_path = 'C:\Users\user\Desktop';
d=dir(fullfile(file_path,'text*.txt'));
for i=1:length(d)
fid=fopen(fullfile(file_path,d(i).name));
...
  댓글 수: 2
tabw
tabw 2014년 8월 7일
d=dir(fullfile(file_path,'text*.txt'));
??? Undefined function or method 'eq' for input arguments of type 'struct'.
this popped up
dpb
dpb 2014년 8월 7일
My bad...the dir somehow got duplicated in the line defining the directory path...
file_path = dir('C:\Users\user\Desktop');
should, of course, simply be
file_path = 'C:\Users\user\Desktop';
Fixed above, just pointing out the problem.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by