刪除文章

我已閱讀過並同意遵守討論區規則, 按這裡檢視討論區規則, 按這裡瞭解引言功能
2007-04-11 9:43 發佈
文章關鍵字 文章
I haven't used Matlab for a long time. Just a few comments based on what I can remember:

> for m=2:101
> A(2,m)=1.2;
> end %將裡面100x100矩陣的第一行的值皆令為1.2

A(2,2:101)=1.2*ones(1,100); might work.

> A(:,102)=0;
> A(:,1)=0;
> A(1,:)=0;
> A(102,:)=0; %將第1,102行以及1,102列的值皆令為零

You already assign zeros to them when you use the function "zeros".

> for l=2:101
> A(101,l)=0.1+(0.003*(l-1)); %將裡面100x100矩陣的最後一行的值以等加級數往右邊增加
> end

A(101,2:101)=0.1:0.003:0.3;

> for i=2:101
> for j=2:101
>
> A(i,j)=0.25*(A(i+1,j)+A(i-1,j)+A(i,j+1)+A(i,j-1));
>
> end
> end

Maybe A(2:101,2:101)=A(1:100,2:101)+A(3:102,2:101)+A(2:101,1:100)+A(2:101,3:102); will work better.

Like I said, I haven't use Matlab for a long time. So I cannot guarantee my comments are correct. However, the rule of thumb is "use array operations to replace explicit loops whenever you can because that's Matlab's strength."
MSH
內文搜尋
X
評分
評分
複製連結
Mobile01提醒您
您目前瀏覽的是行動版網頁
是否切換到電腦版網頁呢?