Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: how to replace element of an array with char?
Replies: 7   Last Post: Aug 6, 2013 12:06 PM

 Messages: [ Previous | Next ]
 prabhakaran m Posts: 39 Registered: 9/18/10
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.

Date Subject Author
8/5/13 prabhakaran m
8/5/13 Roger Stafford
8/5/13 Roger Stafford
8/5/13 prabhakaran m
8/6/13 prabhakaran m
8/6/13 Roger Stafford
8/6/13 prabhakaran m
8/6/13 Steven Lord