Borrar filtros
Borrar filtros

Read in a plain/text file in Matlab

3 visualizaciones (últimos 30 días)
Eli Dim
Eli Dim el 28 de Jul. de 2015
Editada: per isakson el 28 de Jul. de 2015
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 comentario
Eli Dim
Eli Dim el 28 de Jul. de 2015
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?

Iniciar sesión para comentar.

Respuesta aceptada

per isakson
per isakson el 28 de Jul. de 2015
Editada: per isakson el 28 de Jul. de 2015
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'

Más respuestas (1)

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

Categorías

Más información sobre Text Data Preparation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by