Hello,
I want to convert a vector of IP addresses in decimal format to the IPv4 format.
So far I have implemented this using a for loop and the output is a cell array of chars.
function result = dec2IP(decimalIP)% Derive the octets
dec = double(decimalIP);byte1=floor(dec/power(256,3));mod1=mod(dec, power(256,3));byte2=floor(mod1/power(256,2));mod2=mod(mod1, power(256,2));byte3=floor(mod2/power(256,1));mod3=mod(mod2, power(256,1));byte4=floor(mod3/power(256,0));% Convert to char array
for i=1:length(decimalIP) result(i) = {[int2str(byte1(i)), '.', int2str(byte2(i)), '.', int2str(byte3(i)), '.', int2str(byte4(i))]};endend
Is there a way to implement this using vectoring instead of a loop?
Thanks, George
Best Answer