フィルターのクリア

is it possible to get index of reshaped matrix

16 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2014 年 2 月 26 日
コメント済み: Elysi Cochin 2014 年 3 月 1 日
i have a matrix A of size 1*120 and reshaped it to matrix B of size 10*12..... is it possible to get the index values of where the value of A has gone to B in a matrix C of size 1*120....

採用された回答

Iain
Iain 2014 年 2 月 26 日
The functions ind2sub and sub2ind, give you a more general way of doing it, which expands to more dimensions...
  2 件のコメント
Elysi Cochin
Elysi Cochin 2014 年 2 月 26 日
if i have a matrix
A = [22 33 44 55 66 77]
and i reshape it to
B = [22 44 66
33 55 77]
i want C = [1 2 1 2 1 2].... how to do it...
Iain
Iain 2014 年 2 月 26 日
編集済み: Iain 2014 年 2 月 26 日
temporary = 1:numel(A);
C = mod(temporary ,size(B,1))+1;

サインインしてコメントする。

その他の回答 (3 件)

Jos (10584)
Jos (10584) 2014 年 2 月 26 日
A short story of LINEAR vs. SUB indexing:
A = [22 33 44 55 66 77]
B = reshape(A,2,[])
numel(A),numel(B) % the same number of elements
size(A), size(B) % but with different sizes
% However, reshaping does not change the intrinsic order of the elements inside an array.
% This intrinsic order is used by linear indexing:
LinIdx = 3 % any value between 1 and numel(A)
A(LinIdx), B(LinIdx)
% Linear indices correspond to different rows and columns for A and B,
% due to the different shapes between A and B:
LIDX = 1:numel(A) % all linear indices
[rowA, colA] = ind2sub(size(A), LIDX)
[rowB, colB] = ind2sub(size(B), LIDX)
rowB is what you call C

Mischa Kim
Mischa Kim 2014 年 2 月 26 日
編集済み: Mischa Kim 2014 年 2 月 26 日
This would do
An = 1:length(A);
nr = 10;
C(:,1) = floor((An-1)/nr) + 1;
C(:,2) = An' - nr*(C(:,1)-1);
where the first and second cols of C are the column and row indices.

Sagar Damle
Sagar Damle 2014 年 2 月 27 日
C and C1,both are one and the same thing.
A = [22 33 44 55 66 77]
B = reshape(A,2,[])
temp = 1:size(B,1)
C = repmat(temp,1,size(B,2))
C1 = kron( ones(1,size(B,2)) , temp )
  1 件のコメント
Elysi Cochin
Elysi Cochin 2014 年 3 月 1 日
thank you all for the answers.....

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by