Find max, min and create array C

A = [-2 2 3 1 6 4;4 1 0 1 0 -2];
1. Find the maximum and minimum values in the last column
- Should use size() function but how find values in last column?
2. Create a 1X2 array C consisting of all elements in the first row and the last two columns of A.

댓글 수: 6

Hint: the last row/column of a matrix can be referenced using the 'end' keyword, i.e.,
A(:,end) <-- last column of A
A(end,:) <-- last row of A
A(end,end) <-- last row, last column element of A
James Tursa
James Tursa 2013년 9월 11일
What have you done so far?
Matt Kindig
Matt Kindig 2013년 9월 11일
By the way, as A is 2x6, "all elements in the first and last two columns of A" is a total of 6 elements, and thus cannot fit into a "1X2 array C".
Image Analyst
Image Analyst 2013년 9월 11일
Unless it was a 1x2 cell array, but I doubt they'd have that for such an elementary homework problem.
Kondiik
Kondiik 2013년 9월 11일
I thought same thing how can you create array 1x2 when there is 10 elements?
Jan
Jan 2013년 9월 12일
@Kondolik: The Getting Started chapters of the documentation explain the methods for indexing clearly and exhaustively. The forum is not the reight place to ask such very fundamental basics.
You are asked to extract the 2 elements from the first row and the last two columns. Therefore I do not see any problem when A has 10 elements.

댓글을 달려면 로그인하십시오.

답변 (1개)

Youssef  Khmou
Youssef Khmou 2013년 9월 11일

0 개 추천

you can start by creating a temporary variable B=A(:,end), next you can use max(B) and min(B) or you can use the function B=sort(B,'ascend') in ascending order , next the min is B(1) and the maximum is B(end)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

질문:

2013년 9월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by