Selecting a .txt file from different location

If i run the following code i can only select a file from the current working folder:
a1 = uigetfile('../Data/*.txt');
fid1 = fopen((a1), 'r');
c1 = textscan(fid1,'%d%f%s%s%d%d%f%d%d','delimiter', ';','HeaderLines',256);
g1=c1{2};
if i select a file from any other folder other than the working folder il get an error:
Error using textscan Invalid file identifier. Use fopen to generate a valid file identifier.
Error in samp1 (line 7) c1 = textscan(fid1,'%d%f%s%s%d%d%f%d%d','delimiter', ';','HeaderLines',256);
please let me know how to solve this

 採用された回答

Wouter
Wouter 2013 年 3 月 20 日

1 投票

You could try this:
[filename, pathname] = uigetfile('*.txt', 'Pick txt file','/Path/to/folder/Data/');
a1 = fullfile(pathname,filename)

1 件のコメント

shanmukh
shanmukh 2013 年 3 月 20 日
Thank you very much this code works

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeC Shared Library Integration についてさらに検索

製品

タグ

質問済み:

2013 年 3 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by