Borrar filtros
Borrar filtros

Comparing Values from file to cell array

2 visualizaciones (últimos 30 días)
Haba Medhat
Haba Medhat el 29 de Mayo de 2013
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.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 29 de Mayo de 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

Más respuestas (1)

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

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by