if i have two matrix how can make them same size by add zero column or row ?

1 回表示 (過去 30 日間)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016 年 5 月 3 日
編集済み: Stephen23 2016 年 5 月 3 日
if i have this matrix
M = [15 13 11 11 7 7 8 9 11 13 15 8 8 6 3 0 3]
X = [15 13 11 12 7 5 4 7 8 8 11 9 14 11 13 ]
i want to make X the same size of M and after that subtract them like that
X_after = [15 13 11 12 7 5 4 7 8 8 11 9 14 11 13 0 0]
then abs(M - X_after) the final solution will be
Final = [ 0 0 0 1 0 2 4 2 3 5 4 1 6 5 10 0 3]

回答 (2 件)

dpb
dpb 2016 年 5 月 3 日
doc size
doc zeros
Read "Getting Started" section of documentation and work thru the tuorials on basic Matlab syntax and matrix/array operations.

Stephen23
Stephen23 2016 年 5 月 3 日
編集済み: Stephen23 2016 年 5 月 3 日
M = [15,13,11,11,7,7,8,9,11,13,15,8,8,6,3,0,3];
X = [15,13,11,12,7,5,4,7,8,8,11,9,14,11,13];
tmp = zeros(2,max(numel(M),numel(X)));
tmp(1,1:numel(M)) = M;
tmp(2,1:numel(X)) = X;
out = abs(diff(tmp,1,1))
creates:
out =
0 0 0 1 0 2 4 2 3 5 4 1 6 5 10 0 3
And please do the introductory tutorials:

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by