text file columns assistance
이전 댓글 표시
i have a text file with data such as
a1 10
a2 6
etc.
when i use:
function A = ImportData() %ImportData function
FileName = uigetfile('*.txt','Select the MATLAB code file')
assignin('base','A',importdata(FileName))
to import the file, it imports everything under A then if i try to assign a1=A(1,2) it is returning a1 10 instead of just 10. if i use uiimport it wont seperate the columns either. how do i structure the txt file into columns?
답변 (1개)
per isakson
2012년 8월 25일
편집: per isakson
2012년 8월 25일
Strange!
- I don't think ImportData is an appropriate name. It is too close to importdata.
- The output argument, A, is not assigned a value in the function.
I would expect importdata to return a structure in this case.
>> a=importdata('cssm.txt' )
a =
data: [2x1 double]
textdata: {2x1 cell}
rowheaders: {2x1 cell}
>> a.data
ans =
10
6
>> a.textdata
ans =
'a1'
'a2'
>> a.rowheaders
ans =
'a1'
'a2'
where cssm.txt contains
a1 10
a2 6
with space between the columns.
I guess that there is a delimiter between the columns (column separator), which is not recognized by importdata.
See the help:
A = importdata( filename, delimiter )
.
You write "... a1=A(1,2) it is returning a1 10 ...". What does
double( a1 )
return?
카테고리
도움말 센터 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!