Incrementing addresses in string format on Excel or Matlab?
I would like to go from this:
On either excel or matlab. This operation will have to be looped through an entire spreadsheet worth of addresses which is why I'm skeptical that excel has an efficient way of doing it. Please bear in mind the field "Address Number" is a string variable.
I have uploaded the spreadsheet as a Matlab Cell array and am thinking of extracting values one at a time,pre and post hyphen, converting to double and having the script increment and fill a new array but this is quite far fetched and I am not sure which are the relevant commands.
To turn the address number into a series of numbers, the following code should help:
instring = '1428-32'; stub = instring; digits = 0; while ~strcmp(stub(end),'-') stub = stub(1:end-1); digits = digits + 1; end stub = stub(1:end-1); %stub is now your starting number, but as a string maxval = instring(end-(digits-1):end); maxval = strcat(stub(1:end-digits),maxval); outlist = str2double(stub):str2double(maxval);
I'll leave it to you to figure out how to put this back into a larger array with the rest of the data in, it shouldn't be too difficult...