Effacer les filtres
Effacer les filtres

Counting the numbers of times a number appears in a list

1 vue (au cours des 30 derniers jours)
Nada Ismail
Nada Ismail le 5 Juin 2013
Hello,
I have the following code:
clear;close;clc;
prompt = {'Enter File name:'};
dlg_title = 'Quarterly Reports';
num_lines = 1;
answer = inputdlg(prompt,dlg_title,num_lines);
file=answer{1,1};
mon=length(file);
ye=mon-4;
first=file((ye+1):mon);
FName=strcat('PSANumbers',first);
filename=strcat(file,'.txt');
f=fopen(filename);
line1=fgetl(f);
res=[];
k=0;
G=xlsread(FName);
h=length(G);
while ischar(line1)
if ischar(line1)
res =char(res,line1);
idx=regexp(line1,'R[1-9]');
for j=2:h;
p=G{j};
if line1(idx(1))==p
k=k+1;
out{k}=line1;
end
end
line1 = fgetl(f);
end
end
output={line1,out'};
This code is intended to work as follows:
1. Asks user to input file name
2. From that an excel file is opened that has the following information:
PSA Numbers
R00763
R00766
R00759
R00761
R00767
R00768
R00764
R00757
R00879
R00877
R00881
R00880
R00886
R00849
R00818
R00817
R00860
...
and a 'txt' file that holds:
PSA_num Client Name Start_Time End_time Category
R00818 Counseling Center of Milwaukee Inc 8/1/2006 Educational
R00817 Milwaukee County Zoo 8/1/2006 Social
R00860 Wisconsin Humane Society 8/28/2006 Environmental
R00860 Wisconsin Humane Society 8/28/2006 Environmental
R00857 Radiology.Org Health
R00856 Clean Wisconsin 8/25/2006 Environmental
...
3.The code is then supposed to compare every number in the first list (A)to the numbers in the second list (B).
4. For every time a number from list A is found in list B, the 'k' should increase. Once the code has gone through all of list A the output should be:
PSA_num Client Name Start_Time End_time Category Played
R00818 Counseling Center of Milwaukee Inc 8/1/2006 Educational 1
R00817 Milwaukee County Zoo 8/1/2006 Social 1
R00860 Wisconsin Humane Society 8/28/2006 Environmental 2
R00857 Radiology.Org Health 1
R00856 Clean Wisconsin 8/25/2006 Environmental 1
I understand that the end of my code is correct, however I can't even get past 'idx' because it is not reading anything.
  2 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 5 Juin 2013
I think you can make your question more clear, by posting just the part of the code which is not working, and post the error message
Nada Ismail
Nada Ismail le 6 Juin 2013
Okay, thanks!

Connectez-vous pour commenter.

Réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by