How can I match multiple contents of an array to a separate single array?

조회 수: 2 (최근 30일)
George Penny
George Penny 2016년 4월 25일
편집: John BG 2016년 4월 26일
I have a .csv file where multiple postcodes (characters and numbers) correspond to a unique ID number (also characters and numbers).
e.g
  • BS2 9TL, E00073143
  • BS2 9TB, E00073143
  • BS2 9XJ, E00073143
  • BS2 8AT, E00073144
  • BS2 8TY, E00073144
  • BS2 8UA, E00073144
  • BS2 8UG, E00073144
I need to create a new array for each unique ID number that stores the respective postcodes. The amount of postcodes for each ID number is not the same every time.
The file contains 9010 postcodes and 1258 ID numbers.
Can anyone show me how to go about doing this?
Many thanks!

답변 (2개)

Meade
Meade 2016년 4월 25일
  댓글 수: 1
George Penny
George Penny 2016년 4월 25일
Hi, I have understood the unique function can be used to remove duplicates. But how can I separate each group of postcodes to the unique ID numbers I have now?

댓글을 달려면 로그인하십시오.


John BG
John BG 2016년 4월 26일
편집: John BG 2016년 4월 26일
If you really have postcodes along a .csv spreadsheet row, and the codes along another row, then you can do the following:
[a postcode]=xlsread('postcodes1.csv',1,'A1:A7')
[a bcode]=xlsread('postcodes1.csv',1,'B1:B7')
postcode=strtrim(postcode)
bcode=strtrim(bcode)
L_postcode=length(postcode)
[D,di,dj]=unique(bcode)
L_bcode=length(D)
for k=1:L_bcode
D{k}=[D{k} postcode(find(dj==k))']
end
Now you have all basic unique codes on the first row of the cell D.
the second and consecutive elements in each line (row) of D are all post codes with same basic code.
Further processing could be:
for k=1:L_bcode
str1=D{k,:}
% str1(k,1) contains one basic unique code
% str1(k,2) str1(k,2) .. str1(k,end) contains all the post codes
% with same basic code in str1(k,1)
end
If you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by