text file columns assistance

8 views (last 30 days)
Krystina
Krystina on 23 Aug 2012
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?

Answers (1)

per isakson
per isakson on 25 Aug 2012
Edited: per isakson on 25 Aug 2012
Strange!
  1. I don't think ImportData is an appropriate name. It is too close to importdata.
  2. 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?

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!