exist function check file

10 ビュー (過去 30 日間)
zhi zhu
zhi zhu 2017 年 2 月 26 日
編集済み: Stephen23 2017 年 2 月 26 日
I am trying to use
checkfile = exist(inputdlg('Enter the name of the file you wish to analyze input with document type','File name',1),'file');
but it doesn't work
I also tried
filename = (inputdlg('Enter the name of the file you wish to analyze input with document type','File name',1);
exist = (filename,'file')
and that doesn't work either

採用された回答

Stephen23
Stephen23 2017 年 2 月 26 日
編集済み: Stephen23 2017 年 2 月 26 日
The inputdlg help states clearly that the function's "returned variable answer is a cell array", and the exist help clearly states that its input must be a "character vector". So you need to get your character vector out of the cell array and provide it to exist, for example:
>> C = inputdlg('filename:');
>> exist(C{1},'file')==2
ans =
1
or even better would be to use the uigetfile dialog box:
>> [FileName,PathName] = uigetfile('*.m')
FileName =
inner.m
PathName =
C:\Temp\TestDir

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by