フィルターのクリア

Comparing Values from file to cell array

2 ビュー (過去 30 日間)
Haba Medhat
Haba Medhat 2013 年 5 月 29 日
I have set of data such as:
1893 [] C:\RADIOSPOTS\AUDIO\AUDIO\1893.WAV
2514 [] C:\RADIOSPOTS\AUDIO\AUDIO\2514.WAV
3115 Maryknoll C:\RADIOSPOTS\AUDIO\AUDIO\3115.WAV
1891 [] C:\RADIOSPOTS\AUDIO\AUDIO\1891.WAV
1890 [] C:\RADIOSPOTS\AUDIO\AUDIO\1890.WAV
3119 [] C:\RADIOSPOTS\AUDIO\AUDIO\3119.WAV
2891 Shepherd Express C:\RADIOSPOTS\AUDIO\AUDIO\2891.WAV
1893 [] C:\RADIOSPOTS\AUDIO\AUDIO\1893.WAV
I want to get all the rows that have a number starting with "3" and save that into a new array and disregard all the other rows. I started with a for loop with an if statement nested in it that would look something like this:
for cmp=1:Row
if strcmp (3, C(cmp))
PSA(cmp)=C(cmp)
else
nonpsa(cmp)=C(cmp)
end
end
where C is a 95x3 array holding all information, num is only the first column of C (holding only the numbers) and Row is the number of rows in C and num.
However, this doesn't detect the rows that start with '3' and saves only the first column of data in the "nonpsa" array size 1xRow.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 29 日
f=fopen('tes1.txt')
line1=fgetl(f)
res=[];
k=0;
while ischar(line1)
if ischar(line1)
res =char(res,line1)
idx=regexp(line1,'[1-9]');
if line1(idx(1))=='3'
k=k+1
out{k,1}=line1
end
end
line1 = fgetl(f);
end
out

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2013 年 5 月 29 日
f = fopen('yourfile.txt');
c = textscan(f,'%s', 'delimiter', '\n');
fclose(f);
c1 = regexp(c{:},'^3.*','match');
out = [c1{:}]';

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by