Read in a plain/text file in Matlab

조회 수: 5 (최근 30일)
Eli Dim
Eli Dim 2015년 7월 28일
편집: per isakson 2015년 7월 28일
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 Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by