필터 지우기
필터 지우기

How to put data in vector into matrix

조회 수: 1 (최근 30일)
nora elfiky
nora elfiky 2017년 1월 4일
댓글: Roger Stafford 2017년 1월 5일
How to put data in vector into matrix and then changes the position of bits in the matrix. It can be applied in row wise or column wise(Spiral transposition)?

답변 (2개)

Walter Roberson
Walter Roberson 2017년 1월 4일
You can reshape() the vector unless the number of elements is prime.
Consider using the buffer() function from signal processing

Roger Stafford
Roger Stafford 2017년 1월 5일
편집: Roger Stafford 2017년 1월 5일
The following is an example of inserting a row vector, V, into an m by n matrix, M, in a “spiral transposition”. The spiral in this case starts at M(1,1) and spirals inward in a counterclockwise direction. The row vector V must be (at least) m*n in length.
M = zeros(m,n);
a = 0; b = m; c = 1; d = n; f = 0;
while true
a = a+1; e = f+1; f = e+b-a;
if a>b|n==0, break, end
M(a:b,c) = V(e:f).'; % ?
c = c+1; e = f+1; f = e+d-c;
if c>d, break, end
M(b,c:d) = V(e:f);
b = b-1; e = f+1; f = e+b-a;
if a>b, break, end
M(b:-1:a,d) = V(e:f).'; % ?
d = d-1; e = f+1; f = e+d-c;
if c>d, break, end
M(a,d:-1:c) = V(e:f);
end
(Note: The transpose operators at the two question marks are probably not necessary in your system.)
  댓글 수: 1
Roger Stafford
Roger Stafford 2017년 1월 5일
The above spiral is of course only one of sixteen possible spiral types, consisting: (1) of whether the spiral begins or terminates at a corner, (2) of four possible such corners, and (3) of either counterclockwise or clockwise directions. It should be noted that the above code can readily be modified to allow all possible sixteen types to be generated by appropriate combinations of matlab’s ‘fliplr’, ‘flipud’, and ’transpose’ operations carried out afterwards on M, and by possibly initially reversing V, as with V = V(m*n:-1:1).

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by