필터 지우기
필터 지우기

File name is too long using IMREAD in GUI

조회 수: 4 (최근 30일)
Adriano
Adriano 2011년 6월 22일
댓글: Walter Roberson 2015년 10월 13일
Hello everyone,
I made a GUI with the help of GUIDE. In one callback, I am reading an image using IMREAD. However, MATLAB throws an error saying that the file name is too long:
??? Error using ==> fopen
Filename is too long.
Error in ==> imread at 366
fid = fopen(filename, 'r');
I know in Windows, MATLAB allows only an extension of 63 characters and I have already considered that. The current path of the script is:
C:\Users\XXXXXXX Demo
and the images' file name are:
image1.bmp
image2.bmp
...
image30.bmp
The code I am using is the following:
function pbuttonStart_Callback(hObject, eventdata, handles)
...
for i = 1 : 20000
if mod(i, 10)==0
x = handles.data(1,:);
if x > 1
x = 1;
elseif x < -1
x = -1;
end
% Define the number of images available for display.
noImages = length(dir('*.bmp'));
m = (1-noImages) / 2; % Define the m.
b = noImages + m; % Define the b.
imageIndex = round((m*x) + b);
% Read the corresponding image.
I = imread(['image' int2str(imageIndex) '.bmp']);
% Display the image on the corresponding axes.
imshow(I, 'Parent', handles.axesSimulation);
% Define current axes and set properties.
axes(handles.axesSimulation);
axes off;
axes image;
drawnow;
disp('Plotted!');
end
pause(0.001);
end
The curious thing is that if I type on console the command, it works perfectly:
I = imread(['render' int2str(imageIndex) '.bmp']);
Beforehand, thanks for your helps!
A.

채택된 답변

Matt Fig
Matt Fig 2011년 6월 22일
I assume your error is on the line defining I. Put this right before that line and look at what is being passed. You are likely to find what has gone wrong.
['image' int2str(imageIndex) '.bmp']
  댓글 수: 2
Adriano
Adriano 2011년 6월 22일
Thanks for your answer.
Matt Fig
Matt Fig 2011년 6월 22일
Did you discover the cause of the error?

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2011년 6월 22일
There is a possibility that the bit about the file name being too long is not correct. Possibly instead the message should say something like, "too many files open".
I do not know which version(s) it applies to, but there have been reports that imread() [or something in MATLAB triggered by imread()] does not fully return the file open slot to the operating system (e.g., as if it did not fclose() the file), so when many imread() read are done in a loop, you can run out of open files.
  댓글 수: 1
Adriano
Adriano 2011년 6월 22일
Thanks for your answer, will take it into account to.

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


D.
D. 2014년 4월 14일
I had a similar problem. In my case it was caused by the OS specific behaviour of the "ls" command. Under UNIX it put all files for "imread" in one line of a char-array divided by blank spaces instead of listing them in a 2-dimensional char-array. Unfortunately, on http://www.mathworks.de/de/help/matlab/ref/ls.html I don't see that hint:
1) On UNIX platforms, list is a character row vector of names separated by tab and space characters.
2) On Microsoft Windows platforms, list is an m-by-n character array of names—m is the number of names and n is the number of characters in the longest name. MATLAB pads names shorter than n characters with space characters.
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 10월 13일
This problem does not exist if you use dir() instead of ls()

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

카테고리

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