How to put data in vector into matrix
2 ビュー (過去 30 日間)
古いコメントを表示
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)?
0 件のコメント
回答 (2 件)
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
0 件のコメント
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
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).
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!