Comparing Values from file to cell array
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposta accettata
Azzi Abdelmalek
il 29 Mag 2013
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
0 Commenti
Più risposte (1)
Andrei Bobrov
il 29 Mag 2013
f = fopen('yourfile.txt');
c = textscan(f,'%s', 'delimiter', '\n');
fclose(f);
c1 = regexp(c{:},'^3.*','match');
out = [c1{:}]';
0 Commenti
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!