Re: [問題] 基本的繪圖問題已回收
※ 引述《huiyula ( )》之銘言:
: close all; x=linspace(1, 100, 100); % 100個點的x座標
: y=1/x; % 對應的y座標
y=1./x;
: plot(x,y);
: 這樣會跑出錯誤 :
: ??? Error using ==> mrdivide
: Matrix dimensions must agree.
: close all; x=linspace(1, 100, 100); % 100個點的x座標
: y=x^2; % 對應的y座標
y=x.^2;
: plot(x,y);
: ??? Error using ==> mpower
: Matrix must be square.
: close all; x=linspace(1, 100, 100); % 100個點的x座標
: y=3*x; % 對應的y座標
: plot(x,y);
: 正確!
: close all; x=linspace(1, 100, 100); % 100個點的x座標
: y=x*x; % 對應的y座標
y=x.*x;
: plot(x,y);
: ??? Error using ==> mtimes
: Inner matrix dimensions must agree.
: ________________________________________
: 請問以上是為什麼?
: 為什麼有時能畫有時不能?
: 謝謝各位大大的解答~
首先你的x是個1x100的矩陣
1x100的矩陣要怎樣進行1/x的動作呢?
同樣也不能執行x*2,矩陣的次方運算只有矩陣為方陣時才可以進行
最後x*x和前面一樣,1x100的矩陣是不能乘上1x100的矩陣的,維度不對
所以你要用的element operator(matlab demo movie有出現這個名詞)
要進行的是矩陣內相對應位置運算
所以該使用運算符號的是.*、./以及.^
--
Deserves death! I daresay he does. Many that live deserve death. And some die
that deserve life. Can you give that to them? Then be not too eager to deal out
death in the name of justice, fearing for your own safty. Even the wise cannot
see all ends.
Gandalf to Frodo
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.25.235
推
11/27 02:15, , 1F
11/27 02:15, 1F
討論串 (同標題文章)
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章