Read in a plain/text file in Matlab

3 次查看(过去 30 天)
I have a plain/text file which contains the following information:
"Dukovany","Temelin","Prunerov","Pocerady","Chvaletice","Detmarovice","Tusimice II","Melnik II&III","Vresova","Opatovice","Melnik I","Kladno","Ostrava","Komorany","Ledvice","Tisova I","Trebovice","Porici","Plzen","Praha","Steti","Litvinov","Hodonin","Kladno II","Zlin","Krystovofy","Horni","Dlouhe","Dalesice","Orlik","Slapy","Lipno","Stechovice II","Kamyk","Stechovice I","Strekov","Vranov","Vrane","Nechranice","Ralsko","Veprek","Sevetin","Brno","Mimon","Vranovska","Stribro","Chomutov","Uhersky Brod","Chrudichromy","Letkow","Line"
I want to read it in Matlab. I tried
infile = 'PowerPlantNames';
data = load(infile,'-ascii');
But I get the following error: Error using load Unknown text on line number 1 of ASCII file PowerPlantNames ""Dukovany"". How can I read in my information?
  1 个评论
Eli Dim
Eli Dim 2015-7-28
Part of the problem I solved (load can't be used in this case). Using the following command I was able to input the information:
filename = 'PowerPlantNames.txt';
powerplantnames = importdata(filename);
I attached the outputut (powerplantnames). How can I quickly separate the strings?

请先登录,再进行评论。

采纳的回答

per isakson
per isakson 2015-7-28
编辑:per isakson 2015-7-28
Try
>> out = cssm();
>> out{1}(12:14)
ans =
'Kladno'
'Ostrava'
'Komorany'
where
function cac = cssm()
fid = fopen( 'PowerPlantNames.txt' );
cac = textscan( fid, '%q', 'Delimiter',',' );
fclose( fid );
end
and PowerPlantNames.txt contains the data of your question
Or using the file 1.mat
>> load 1
>> cac = textscan( powerplantnames{1}, '%q', 'Delimiter',',' );
>> cac{1}(12:14)
ans =
'Kladno'
'Ostrava'
'Komorany'

更多回答(1 个)

Muthu Annamalai
Muthu Annamalai 2015-7-28
Original question is answered by
  1. doc fileread
See split manipulation functions
  1. doc strsplit
  2. doc regexprep

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by