필터 지우기
필터 지우기

How to reverse a number?

조회 수: 2 (최근 30일)
Jessica
Jessica 2014년 11월 18일
답변: saurabh jare 2023년 3월 7일
Hi,
I want to reverse a number without using MATLAB functions "digitrevorder()" and "fliplr()". Please help. Thank you!

답변 (3개)

Evan
Evan 2014년 11월 18일
x = 1234;
s = num2str(x) - '0';
xr = polyval(s(end:-1:1),10)
  댓글 수: 7
John D'Errico
John D'Errico 2014년 11월 18일
편집: John D'Errico 2014년 11월 18일
A moderately interesting question is to find a solution in one line, without needing to form an intermediate variable. (And without the application of fliplr!) Seems trivial with that function.
Guillaume
Guillaume 2014년 11월 18일
편집: Guillaume 2014년 11월 18일
You also want to disallow rot90, flipud and flip, otherwise it's also trivial.

댓글을 달려면 로그인하십시오.


Syed Haider
Syed Haider 2014년 11월 18일
A = [1 2 3 4; 5 6 7 8];
y = A(:,end:-1:1)
  댓글 수: 3
Syed Haider
Syed Haider 2014년 11월 18일
Yeah you are right :) I am sorry. Should i remove the answer? or may be it will be helpful for someone.
John D'Errico
John D'Errico 2014년 11월 18일
I don't see any reason to remove it.

댓글을 달려면 로그인하십시오.


saurabh jare
saurabh jare 2023년 3월 7일
function ran=reverse_number(x)
%x=input('Enter the value for checking the palindromic= \n');
check=x;
ran=0;
while (check~=0)
ran=(ran*10)+mod(check,10);
check=fix(check/10);
end

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by