Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.