i want to create an error msg in matlab gui

I want to run a program where a excel file will be taken as input and i want that if the excel file is not find there should be an error msg. how can i create that type of error msg box. here file name is stored in a variable named a. please help me. thank you in advance..

1 件のコメント

partha das
partha das 2011 年 7 月 13 日
plz tell me the condition for the error msg.

サインインしてコメントする。

 採用された回答

Friedrich
Friedrich 2011 年 7 月 13 日

0 投票

Hi,
You have to use the exist function. If the Excel file is not on the MATLAB path you will need the absolut path to it. And than do
if exist(a,'file') ~= 2
msgbox('File Not found','Error','Error');
else
%file is there, do something with it
end
Where a should look like
a = 'C:\folder_with_file\name_of_file.xls'
a =
C:\folder_with_file\name_of_file.xls

1 件のコメント

partha das
partha das 2011 年 7 月 13 日
thank you.. very much sir...

サインインしてコメントする。

その他の回答 (1 件)

Chirag Gupta
Chirag Gupta 2011 年 7 月 13 日

0 投票

The previous answer seems to work. What are the contents of the variable? Is the variable a cell?
filename = 'MyTest1.xls'
if (~exist(filename,'file'))
msgbox('File Not Found','Error','Error');
end
What is the error if any that you are getting? Note that if the variable filename is a cell, you will need to pass the name explicitly like:
exist(filename{1},'file')

6 件のコメント

partha das
partha das 2011 年 7 月 13 日
actually i stored the file name in a. now when i give the commend if (~exist(a,'file'))
msgbox('File Not Found','Error','Error');
end. when file is present then it also giving the error msg.. plz help.
partha das
partha das 2011 年 7 月 13 日
it is not cell type array.. its a simple matrix.
Friedrich
Friedrich 2011 年 7 月 13 日
I repeat again: If the Excel file is not on the MATLAB path you will need the absolut path to it.
partha das
partha das 2011 年 7 月 13 日
excel file is in the matlab path.... till not working.
Friedrich
Friedrich 2011 年 7 月 13 日
it works fine for me. please post your code and the content of the variable a
partha das
partha das 2011 年 7 月 13 日
thank you.. very much sir..

サインインしてコメントする。

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by