File name is too long using IMREAD in GUI
이전 댓글 표시
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.
채택된 답변
추가 답변 (2개)
Walter Roberson
2011년 6월 22일
1 개 추천
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.
D.
2014년 4월 14일
0 개 추천
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
2015년 10월 13일
This problem does not exist if you use dir() instead of ls()
카테고리
도움말 센터 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!