How do I check if a file on a website exists?
7 次查看(过去 30 天)
显示 更早的评论
I want to read in image files from my online database.
I would like to check my website to see if the file exists before attempting to load it into the workspace.
For Example I would like to do (simplified):
E = exist('http://www.mywebsite.com/images/1.png);
if E ~= 0
IMG = imread('http://www.mywebsite.com/images/1.png);
else
IMG = zeros(X,Y);
end
Thanks in Advance!
0 个评论
采纳的回答
Sean de Wolski
2012-10-24
You could just use a try/catch block.
try
IMG = imread('http://www.mywebsite.com/images/1.png);
catch
IMG = zeros(X,Y);
end
更多回答(1 个)
Erick Oberstar
2015-12-15
you can use urlread also
[str,status] = urlread('http://www.mywebsite.com/images/1.png');
if status
IMG = imread('http://www.mywebsite.com/images/1.png');
else
disp('URL read of link was unsuccessful')
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!