필터 지우기
필터 지우기

import file by specifying its location - without GUI

조회 수: 2 (최근 30일)
Tomas
Tomas 2013년 5월 21일
Hi, is there any function in "Matlab" that allows to specify file (.txt) location and import its data without using GUI?
Thanks in advance
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 5월 21일
How much interactivity is expected? e.g., should the use be able to go up and down levels of directories and see the filenames in the directories, all done through text?
Tomas
Tomas 2013년 5월 21일
편집: Tomas 2013년 5월 21일
I expect a function where I could just enter variables=neededFunction('C:\readthisfile.txt') (readthisfile.txt is not in "Matlab" path.)

댓글을 달려면 로그인하십시오.

답변 (3개)

Walter Roberson
Walter Roberson 2013년 5월 21일
If you are processing text files, then they do not normally have variables, just data and headers. Are you expecting there to be column headers and expecting that MATLAB will synthesize variable names from the column headers?
Is the .txt file just a mix of comments ('%' at beginning of lines) and rectangular columns of data? If so then you can load() -ASCII the .txt file.
You might be able to use uiimport() to deduce the pattern associated with the text file.
If you know what the pattern of the text file is supposed to be then you are usually best off using textscan()
  댓글 수: 2
Tomas
Tomas 2013년 5월 21일
Yes, you are right, the .txt file has only data and its looks like:
aaa
aaa bbb
aaaa bb aaaa
2.0 0.01
1.0 0.02
........
359.0 0.02
Can I use full path instead of fileID when using textscan funtion?
C = textscan(fileID,formatSpec), where fileID is 'D:\needToRead.txt' ?
Iain
Iain 2013년 5월 21일
No. You need to open a file to get a file ID (fid = fopen(filename,'r'); for reading), and once you're done with the file, you need to close it (fclose(fid)), and if you need to re-read, you'll either need to reopen it, or use fseek.

댓글을 달려면 로그인하십시오.


Iain
Iain 2013년 5월 21일
Yes. You can use low level functions to read text files of any format, provided you tell matlab exactly what to do to read the data from the files: (fopen, fread, fclose.)
There are some functions that read lines from open files (eg. textscan)
There are some functions that read simply formatted files eg. dlmread, csvread, load.

Tomas
Tomas 2013년 5월 21일
Its simply importdata('fullpath.txt', '',5), thanks guys for your time :)

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by