MATLAB Answers

how to read or write a file according to its absolute path

52 ビュー (過去 30 日間)
Salvatore Mazzarino
Salvatore Mazzarino 2012 年 9 月 29 日
I read a txt file using importdata. I pass the name of txt file to that function. Instead to pass only the name I would pass the absolute path. The same thing when I write data on file using dlmwrite. I would pass to that function the absolute path where save the file.

  0 件のコメント

Sign in to comment.

採用された回答

Razvan
Razvan 2012 年 9 月 29 日
I don't see any problem. I'm sure every Matlab function can deal with local files as well as with absolute paths.

  3 件のコメント

Salvatore Mazzarino
Salvatore Mazzarino 2012 年 9 月 29 日
I had found mfilename that return the absolute path of the file where it is executed. But mfilename return besides the absolute path even the name. I'm not interesed in the name but only to absolute path
Razvan
Razvan 2012 年 9 月 29 日
If you need the current dir then
yourPath = pwd
Salvatore Mazzarino
Salvatore Mazzarino 2012 年 9 月 29 日
thanks so much Razvan. It was so easy

Sign in to comment.

その他の回答 (1 件)

Image Analyst
Image Analyst 2012 年 9 月 29 日
Do something like this:
folder = pwd;
absoluteFileName = fullfile(folder, relativePath, baseFileName);
where folder is the current folder, say 'C:\users\Razvan\Documents' or whatever other folder you want. relativePath is something like '\subFolder1\subfolder2', and baseFileName is something like 'myData.txt'. So the final folder would be 'C:\users\Razvan\Documents\subFolder1\subfolder2\myData.txt'. fullfile() takes care of figuring out whether to use forward or backslashes and making sure that you don't have two of them when the strings are concatenated.

  0 件のコメント

Sign in to comment.

タグ


Translated by