Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
reverse order

Subject: reverse order

From: joshuaBrady@hotmail.com (Joshua)

Date: 30 Oct, 2004 12:16:10

Message: 1 of 3

hi guys i'm in desperate need of help. I need to input a string then
reverse the order of the elements. here is the code that I have:
If this were java I would go to the end of the string ie
reverse.length()-1 and reverse from there but can anyone help me using
matlab.
I know you can reverse a vector using fliplr but it doesn't work in
this scenario

reverse = input('enter a digit:');
if (reverse == 1)
    fprintf('the reverse is:%d ',reverse)
elseif (reverse ~=1)
    reverse = fliplr(reverse)
    fprintf('the reverse is:%f ',reverse)
end;

Thanks for any help
Joshua

Subject: reverse order

From: Michael Robbins

Date: 30 Oct, 2004 12:34:38

Message: 2 of 3

> hi guys i'm in desperate need of help. I need to input a string
> then
> reverse the order of the elements. here is the code that I have:
> If this were java I would go to the end of the string ie
> reverse.length()-1 and reverse from there but can anyone help me
> using
> matlab.
> I know you can reverse a vector using fliplr but it doesn't work in
> this scenario
>
> reverse = input('enter a digit:');
> if (reverse == 1)
> fprintf('the reverse is:%d ',reverse)
> elseif (reverse ~=1)
> reverse = fliplr(reverse)
> fprintf('the reverse is:%f ',reverse)
> end;

Try flipud(), or flipud(fliplr()) to be sure, or reverse(end:-1:1)

Subject: reverse order

From: Leendert Combee

Date: 30 Oct, 2004 17:43:13

Message: 3 of 3

> hi guys i'm in desperate need of help. I need to input a string
> then reverse the order of the elements. here is the code that I
> have. I know you can reverse a vector using fliplr but it doesn't
> work in this scenario

Obviously this doesn't work because all your syntax use is wrong.
It would be _really_ helpful if you checked "help input" first.

You say that you want to input a string, but then you test it as if
it is a digit/number (if reverse==1), and also you print it as if it
was a number. So, you need to sort out first what you want your
input to be! A string, or a number (these are two different things)

If you enter a string (like 'test', or '4510'), the test whether
reverse==1
doesn't make much sense. And you need to print as a string, i.e.,
use %s instead of %f. fprintf('the reverse is %s',fliplr(reverse))
will
work perfectly fine.

If you enter a number, like 4510 and what the output to be reversed
copy of this number, i.e., 0154, you have to convert to a string
first:
fprintf('the reverse is %s',fliplr(int2str(reverse)); or
fprintf('the reverse is %s',fliplr(sprintf('%i',reverse)));

Hope this helps.

> reverse = input('enter a digit:');
> if (reverse == 1)
> fprintf('the reverse is:%d ',reverse)
> elseif (reverse ~=1)
> reverse = fliplr(reverse)
> fprintf('the reverse is:%f ',reverse)
> end;

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us