>> A = [1 2;3 4;5 6] A = 1 2 3 4 5 6 >> A(3,2) ans = 6
>> A(2,:) %该行或列的所有元素 ans = 3 4 >> A(:,2) ans = 2 4 6 >> A([1 3], :) %取第一、三行的元素 ans = 1 2 5 6
>> A(:,2) = [0; 0; 0] %赋值给A的第二列 A = 1 0 3 0 5 0 >> A = [A,[10;11;12]];%再加一列 >> A A = 1 0 10 3 0 11 5 0 12 >> A(:)%把A所有的元素一向量形式表示 ans = 1 3 5 0 0 0 10 11 12
>> A A = 1 0 10 3 0 11 5 0 12 >> B = [36 12;23 0; 56 12] B = 36 12 23 0 56 12 >> C =[A B] C = 1 0 10 36 12 3 0 11 23 0 5 0 12 56 12 >> C = [A;B]%AB行数一样就可以 error: vertical dimensions mismatch (3x3 vs 3x2) >> A = [1 0;3 0;5 0] A = 1 0 3 0 5 0 >> C = [A;B] C = 1 0 3 0 5 0 36 12 23 0 56 12 >> A =[1;2;3] A = 1 2 3 >> C = [A;B] error: vertical dimensions mismatch (3x1 vs 3x2) >>
%这2种方式一样的 >> [A,B] ans = 1 36 12 2 23 0 3 56 12 >> [AB] error: 'AB' undefined near line 1 column 2 >> [A B] ans = 1 36 12 2 23 0 3 56 12