from an array, creating a row vector of elements but one row is in reverse order

6 visualizaciones (últimos 30 días)
Starting with
>> y=[5 6 7 0 -2; 1 5 6 5 3; -6 -2 0 -3 -5; 0 1 1 6 8]
y =
5 6 7 0 -2
1 5 6 5 3
-6 -2 0 -3 -5
0 1 1 6 8
What is the one-line command to create a 1-by-10 row vector containing the elements of the second row and third row, where the third row has been reversed left-to-right
  8 comentarios
Christa Weber
Christa Weber el 13 de En. de 2023
Im supposed to do it in one line, im just not sure how and I cant find any examples
Steven Lord
Steven Lord el 13 de En. de 2023
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.

Iniciar sesión para comentar.

Respuestas (3)

Image Analyst
Image Analyst el 13 de En. de 2023
If it's not your homework, try this:
y=[5 6 7 0 -2; 1 5 6 5 3; -6 -2 0 -3 -5; 0 1 1 6 8]
y = 4×5
5 6 7 0 -2 1 5 6 5 3 -6 -2 0 -3 -5 0 1 1 6 8
result = [y(2,:), fliplr(y(3,:))]
result = 1×10
1 5 6 5 3 -5 -3 0 -2 -6
If it is your homework and you turn in my code as your own, you could get into trouble if you get caught by your instructor.

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 13 de En. de 2023
Use : and fliplr(). See DOC1 and DOC2.

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 13 de En. de 2023
Eg.:
A = [ 1, 2 3; 4 5 6; 7 8 9]
% Extract Row 1
a1 = A(1,:);
% Extract Row 3
a3 = A(3.:);
% Reverse Row 1
a1 = fliplr(a1)
% Concatenate
B = [a1, a3]
% Now apply these steps with your exercise in one row of command by
% combining these three steps together

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by