Beginner - How to print the external values of an array in Matlab? -


## want write function receives array parameter , prints array's external values better using loops.

e.g. if = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12]

then call printframe(a) display in code shows.

this far can obtain array 0 in middle, not sure if way can lead me final purpose ---- printing frame of array##

% text not showing clear enough want display following 1   2   3    4 5            8 9   10  11  12    function f = printframe(a) mat = []; [m,n]=size(a); i=1:n e = a(1,i); mat = [mat,e];    end j=2:(m-1) e = a(j,1); mat = [mat,e];    k = 2:(n-1)    a(j,k)=0;    g = a(j,k);    mat = [mat,g];    end e = a(j,end); mat = [mat,e]; end i=1:n h = a(end,i); mat = [mat,h]; end  l = 1:length(mat); f = fprintf('%5d',mat(l));  if rem(l,n) == 0     fprintf('\n');  end end  fprintf('\n\n') end 

use bsxfun create mask , apply logical index. a needs transposed order want (rows first, columns).

b = a.'; %' mask = bsxfun(@or, [1 zeros(1,size(b,2)-2) 1], [1; zeros(size(b,1)-2,1); 1]); result = b(mask).'; %' disp(result) 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -