Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



how to replace element of an array with char?
Posted:
Aug 5, 2013 9:16 PM


Dear all, i have written a programme to convert decimal no to hexa.
clear all r=input('\n enter the decimal number to convert in octal='); n=1000; dis=[]; for i=1:n quo=floor(r/16) dis(i)=rem(r,16) r=quo;
if quo <= 0 break end if dis(i) == 10 dis(i)=char('A') elseif dis(i)==11 dis(i)=char('B') elseif dis(i)==12 dis(i)=char('C') elseif dis(i)==13 dis(i)= char('D') elseif dis(i) ==14 dis(i)=char('E') elseif dis(i)==15 dis(i) =char('F') end end X=fliplr(dis) disp(sprintf('The equivalent octal number is : %s',num2str(X)))
if i input 45 i should get 2D as answer but i am getting 2 68. matlab shows me a numeric value equivalent to D. how i should ignore it.please help with this.



