# creating a function to output the invert the numbers in an array

1 visualizzazione (ultimi 30 giorni)
Alexandra il 28 Ott 2012
A = [ 1 2 3 4 5 6]
A = 6 5 4 3 2 1
when an array is entered, the function will display all elements on a row and all rows in inverted order.
I am having trouble creating a function to do the above for both vectors and matrices. I am to do this without using flip functions.
any help is appreciated ~
Alexandra
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Walter Roberson il 29 Ott 2012

Accedi per commentare.

### Risposte (3)

Image Analyst il 28 Ott 2012
This sounds like a homework problem ( http://www.mathworks.com/matlabcentral/answers/8626-how-do-i-get-help-on-homework-questions-on-matlab-answers). Hint: use a for loop with an increment of -1 to go backwards:
for row = lastRow: -1 : 1
same for the columns. To determine the last row, use the size() function. Use fprintf() or disp() to display. Also, type
doc colon
on the command line to learn how the colon operator works. Post back here with your attempt if you're still having trouble.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Chris A il 28 Ott 2012
A = [ 1 2 3 4 5 6]';
b=reshape(sortrows(horzcat(A, ((numel(A):-1:1)')), [2]),[],1);
b(1:6),
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Andrei Bobrov il 29 Ott 2012
Modificato: Andrei Bobrov il 29 Ott 2012
ii = numel(A):-1:1;
B = A(ii);
or
B = A(sort(1:numel(A),'descend'));
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by