creating sub arrays
Ältere Kommentare anzeigen
Hi, I am just going through a MATLAB text book and one of the examples seem to confuse me. I have written the example below. Could some one explain the logic to the displayed results a = [2 3 4; 2 15 6;2 65 4;]; b= a([2 2 2],:) gives the matrix (3x3) 2 15 6 2 15 6 2 15 6
Why does this happen as opposed to 1x9 row vector 2 15 6 2 15 6 2 15 6 ?
I would have thought that we need to explicitly put semicolons to get a 3x3 square matrix because only the semicolon can start a new row for a matrix?? b= a([2;2;2;],:)
Can someone please explain how matlab 'steps into' this code in a real simple way?
Antworten (1)
Matt Fig
am 8 Feb. 2011
a = [2 3 4; 2 15 6;2 65 4]
b = a([2;2;2],:)
Reads as: take all columns of row 2, three times and assign it to b. Whatever is to the left of the comma is an index into the rows of a, and whatever is to the right of the comma is an index into the columns of a.
Try this:
b = a([2 3],[2,3]) % Take columns 2 and 3 of rows 2 and 3.
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!