##我想寫一個接收數組作爲參數的函數,然後使用循環更好地打印數組的外部值。初學者 - 如何在Matlab中打印數組的外部值?
例如如果A = [1,2,3,4; 5,6,7,8; 9,10,11,12]
然後調用printFrame(A)將顯示在代碼顯示中。
這是盡我所能,以便我得到一個只有0在中間的數組,不知道這種方式能否導致我的最終目的----打印陣列的幀##
% the text was not showing clear enough I want it to display like the following
1 2 3 4
5 8
9 10 11 12
function F = printFrame(A)
mat = [];
[m,n]=size(A);
for i=1:n
e = A(1,i);
mat = [mat,e];
end
for j=2:(m-1)
e = A(j,1);
mat = [mat,e];
for k = 2:(n-1)
A(j,k)=0;
g = A(j,k);
mat = [mat,g];
end
e = A(j,end);
mat = [mat,e];
end
for i=1:n
h = A(end,i);
mat = [mat,h];
end
for l = 1:length(mat);
F = fprintf('%5d',mat(l));
if rem(l,n) == 0
fprintf('\n');
end
end
fprintf('\n\n')
end
你真的需要定義什麼是這種「外部價值」 ......沒有任何意義,我(除非有人能解釋一下)...... – ha9u63ar 2015-04-01 13:29:50
對不起,但我已經添加了我希望在我的代碼中的格式,希望這會更有意義。謝謝。 – Chaney 2015-04-02 00:42:05