0
A
回答
0
這是我現在該怎麼做了,但有一定是更優雅的方式吧?!
%% construct G
% upper half
firstDiagG = ones(h, 1);
firstDiagG(h) = 0;
firstDiagG = -firstDiagG;
firstDiagG = repmat(firstDiagG,w,1);
% first = diag(firstDiagG);
firstG = spdiags(firstDiagG,0,n,n);
secondDiagG = ones(h, 1);
secondDiagG(h) = 0;
secondDiagG = repmat(secondDiagG,w,1);
% second = diag(secondDiagG);
secondG = spdiags(secondDiagG,0,n,n);
secondG = [zeros(size(secondG,1),1) secondG];
secondG = secondG(:,1:end-1);
upperHalf = firstG + secondG;
% lower half
thirdDiagG = ones(n-h, 1);
thirdDiagG = [thirdDiagG; zeros(h, 1)];
thirdDiagG = -thirdDiagG;
% thirdG = diag(thirdDiagG);
thirdG = spdiags(thirdDiagG,0,n,n);
fourthDiagG = [ones(n-2*h, 1); zeros(n-2*h, 1)];
% fourthG = diag(fourthDiagG);
fourthG = spdiags(fourthDiagG,0,n,n);
fourthG = [zeros(size(fourthG,1), h) fourthG];
fourthG = fourthG(:,1:end-h);
% fourthG = [fourthG zeros(size(fourthG,1),h)];
% fourthG = [fourthG; zeros(size(fourthG,1), size(fourthG,2))];
lowerHalf = thirdG + fourthG;
G = [upperHalf; lowerHalf];
%% construct D
% left half
firstD = firstG; % is the same as in G
secondDiagD = secondDiagG; % is the same as in G
% secondD = diag(secondDiagD);
secondD = spdiags(secondDiagD,0,n,n);
secondD = [zeros(1, size(secondD,1)); secondD];
secondD = secondD(1:end-1,:);
leftHalf = firstD + secondD;
% right half
thrirdDiagD = flip(thirdDiagG);
% thirdD = diag(thrirdDiagD);
thirdD = spdiags(thrirdDiagD,0,n,n);
fourthDiagD = ones(n, 1);
% fourthD = diag(fourthDiagD);
fourthD = spdiags(fourthDiagD,0,n,n);
fourthD = [zeros(h, size(fourthD,1)); fourthD];
fourthD = fourthD(1:end-h,:);
rightHalf = thirdD + fourthD;
D = [leftHalf rightHalf];
相關問題
- 1. MATLAB-如何繪製散點圖矩陣
- 2. 如何製作一個三角形漸變的Matlab矩陣?
- 3. 創建這個矩陣在MATLAB
- 4. 如何加載這種矩陣在MATLAB
- 5. 如何乘這個矩陣在MATLAB
- 6. 如何生成在MATLAB這個矩陣
- 7. 從Matlab中的矩陣構建地圖
- 8. 如何在MATLAB中輕鬆構建Levi-Civita 3x3x3矩陣?
- 9. Matlab的:在結構矩陣
- 10. MATLAB矩陣變換
- 11. 如何在R中構建矩陣
- 12. 如何在python中構建這個塊矩陣?
- 13. 如何在Matlab矩陣
- 14. Matlab的變換2D矩陣3D矩陣
- 15. 從MATLAB中的矩陣和矢量創建三維矩陣
- 16. 矩陣在Matlab中
- 17. MATLAB - 用子矩陣創建矩陣
- 18. 如何在C++中編寫3x3矩陣漸變?
- 19. MatLab的矩陣結構
- 20. 矩陣矩陣在Matlab中的數組?
- 21. contourf,colormap,colorbar在matlab中創建漸變
- 22. 如何在MATLAB中集成矩陣(矩陣和dx間距之和)?
- 23. 這些矩陣如何工作?
- 24. 在MATLAB矩陣
- 25. 如何使用MATLAB中的漸變標記顏色創建散點圖?
- 26. 如何根據一些標準在Matlab中刪除矩陣行?
- 27. 如何構建平均3D矩陣的Scilab/MATLAB程序?
- 28. 在MATLAB中創建符號矩陣R2009b
- 29. 在matlab中創建三維矩陣
- 30. 學習在MATLAB中創建帶矩陣
我會嘗試一下,但我無法複製並粘貼您的示例以驗證我的解決方案。也許如果你用文字而不是圖像來表達矩陣。 – beaker