Expanding Addresses in Matlab
2 views (last 30 days)
Show older comments
I have an interesting problem in a dataset that I've trying to solve in Matlab (R2014b) and hoped to get some help since I am stuck.
I have a file of addresses that have been shortened so that the house number only includes the beginning number and the end number for a series of houses(for example, the list of houses of 1 Main St, 3 Main St, 5 Main St, and 7 Main St, are displayed as 1-7 Main St.)
I've been trying to create a script that would allow me to expand the address back out so I can get the full list. In an ideal world, I'd like to get the full address back out but I can't seem to get to the intermediate step of getting just the expanded house numbers.
This is the code I've tried so far is below and I've attached a snippet of the data. I keep getting an unbalanced error but I am having trouble visualizing how the underlying new matrix needs to be constructed.
Thanks in advance.
tmp=[];
for i=1:length(num1)
begin=num1(i);
final=num2(i);
tmp1=zeros((final-begin)/2);
tmp=[tmp;tmp1];
for j=1:2:((final-begin)/2+1)
num=j;
new_address(i*(j-1)/2)=(num fullst);
end
end
0 Comments
Answers (1)
Star Strider
on 19 Nov 2015
See if this does what you want:
Nrs = 1:7; % Address Numbers
st = 'Main Street'; % Street Name
for k1 = 1:length(Nrs)
full_addr{k1} = sprintf('%d %s', Nrs(k1), st);
end
celldisp(full_addr)
2 Comments
Star Strider
on 19 Nov 2015
This seems to work, even though the combination of a string and numeric variables require loops:
[d,s] = xlsread('NBI for matlab.csv');
NrRng = d;
StName = s(2:end,3);
for k1 = 1:size(StName,1)
Nr = NrRng(k1,1):NrRng(k1,2);
for k2 = 1:length(Nr)
full_addr{k1,k2} = sprintf('%d %s\n', Nr(k2), char(StName(k1)));
end
end
full_addr{1,1}
full_addr{6,5}
The last two lines just show a sample of the results. To display them all, use the celldisp function.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!