from an array, creating a row vector of elements but one row is in reverse order
6 views (last 30 days)
Show older comments
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 Comments
Steven Lord
on 13 Jan 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.
Answers (3)
Image Analyst
on 13 Jan 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]
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.
0 Comments
Sulaymon Eshkabilov
on 13 Jan 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
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!