필터 지우기
필터 지우기

How do I check if a file on a website exists?

조회 수: 14 (최근 30일)
John
John 2012년 10월 24일
댓글: Ali Abed 2017년 10월 15일
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!

채택된 답변

Sean de Wolski
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
John
John 2012년 10월 24일
Thanks for the fast response... I didn't know that try and catch blocks existed. This is going to help me a lot with loads of other codes!

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

추가 답변 (1개)

Erick Oberstar
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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by