open files from different directorys

I have to load data from a .m file to a uitable, thats my code:
diretorio = uigetdir;
filename = uigetfile('*.mat','Select the MATLAB code file');
d = ' \';
e = strtrim(d); % Usado para salvar "/" em forma de string
Dados_1 = strcat(diretorio,e,filename);
Dados_2 = open(Dados_1);
As you can see, its not functional, once i need to ask for the directory name, the file name, then manipulate strings and finally open it. Is there a function that opens files from different directorys?

 採用された回答

Image Analyst
Image Analyst 2011 年 10 月 2 日

0 投票

Accept BOTH return values from uigetdir(), then combine them with fullfile().

5 件のコメント

Guilherne
Guilherne 2011 年 10 月 2 日
It was very usefull, but i want to know if is there a function that get the directory name when i select the file, or something like that, because its not functional ask the name of both directory and file name, once this code will be used to interact with the user, tks!
Fangjun Jiang
Fangjun Jiang 2011 年 10 月 2 日
I think you mean the two return arguments of uigetfile().
Image Analyst
Image Analyst 2011 年 10 月 2 日
I don't know why you say that. It's almost like you didn't even look at the help for uigetdir and fullfile. If you had, you would have seen that it's a simple process to do get both return values/arguments and combine them like this:
[baseFileName, folder] = uigetfile('*.*', 'Specify a file');
fullFileName = fullfile(folder, baseFileName);
Guilherne
Guilherne 2011 年 10 月 9 日
Sorry, I didnt understood well when I readed at the first time, I just got that fullfile will help me to put the names together, but didnt realized about the uigetfile. In fact I even dont need the fullfile anymore because I can use the function load to open:
[filename, caminho] = uigetfile('*.mat','Select the MATLAB code file');
Data_1 = load([caminho filename]);
Jan
Jan 2011 年 10 月 9 日
I recommend to use "load(fullfile(caminho filename));" instead. In opposite to the simple concatenation it cares for the necessary file separators.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by