12.07.2015 Views

Matlab/Octave Tutorial

Matlab/Octave Tutorial

Matlab/Octave Tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

MATLAB 程 式 設 計 入 門 篇 : 初 探 MATLAB矩 陣 的 最 大 元 素• 找 出 一 矩 陣 最 大 元 素 的 位 置• 範 例 9-21: max01.mx = magic(5);[colMax, colMaxIndex] = max(x)colMax =23 24 25 21 22colMaxIndex =2 1 5 4 3• colMax 代 表 每 一 直 行 的 最 大 值 ,colMaxIndex 則 是 每 一 直 行 出 現 最 大 值 的 位 置• 求 得 x 的 最 大 元 素 的 位 置• 範 例 9-22: max02.mx = magic(5);[colMax, colMaxIndex] = max(x);[maxValue, maxIndex] = max(colMax);fprintf('Max value = x(%d, %d) = %d\n', colMaxIndex(maxIndex), maxIndex, maxValue);Max value = x(5, 3) = 25• x 的 最 大 元 素 即 是 maxValue, 發 生 位 置 為 [colMaxIndex(maxIndex), maxIndex] = [5 , 3]• 若 只 要 找 出 一 矩 陣 x 的 最 大 值 , 可 輸 入 max(max) 或 是 max(x(:))85

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!