from an array, creating a row vector of elements but one row is in reverse order
Mostrar comentarios más antiguos
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
Torsten
el 13 de En. de 2023
help fliplr
Rik
el 13 de En. de 2023
What have you tried?
Christa Weber
el 13 de En. de 2023
Torsten
el 13 de En. de 2023
- Extract the second row from y.
- Extract the third row from y.
- Reverse the third row.
- Concatenate the second row and the reversed third row to a new row vector.
Christa Weber
el 13 de En. de 2023
Christa Weber
el 13 de En. de 2023
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.
Respuestas (3)
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]
result = [y(2,:), fliplr(y(3,:))]
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
el 13 de En. de 2023
0 votos
1 comentario
Christa Weber
el 13 de En. de 2023
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 Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!