text file columns assistance

9 ビュー (過去 30 日間)
Krystina
Krystina 2012 年 8 月 23 日
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
per isakson 2012 年 8 月 25 日
編集済み: per isakson 2012 年 8 月 25 日
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?

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by