how to read or write a file according to its absolute path
조회 수: 34 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
추가 답변 (1개)
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
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!