フィルターのクリア

Read in a plain/text file in Matlab

3 ビュー (過去 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 Center および File ExchangeText Data Preparation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by