change the dimension of multidimensional matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
hi.... can any one help me in debugging the code . i want to fix the number of rows and number of column to be of variable size or i want to fix number of columns and variable number of rows . in one execution one will be of fixed length and other parameter will be of variable length i have the sample code for your kind reference.
N=64;
C=16;
Nt=2;
p=[1 -1 1j -1j];
randn('state', 12345);
B=randsrc(C,N,p);
for ii=1:Nt
for n=1:size(B,1)
B1(n,:,:)=B;
end
end
B is of size 16 x 64 and after executing B1 i am getting it as 100 x 192 x 2 . i want to retain the size of columns to be 100 x 64 x2 . i want a help on this code.
댓글 수: 0
답변 (2개)
Jan
2018년 2월 15일
I do not understand the question. You have a 16 x 64 matrix and want to get a 100 x 64 x 2 matrix. 100 is not a multiple of 16, so I do not have an idea of what you want exactly. But in general this is done by these commands: repmat, reshape, permute. Any kind of reordering or changing the shape or size of an array can be done using these commands.
댓글 수: 4
Jan
2018년 2월 15일
@ABDUL: Please read http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup . If you format your code, it will be readable.
I do not understand what "retain the code as 16 x 64 x 2 as matrix dimension" means. Maybe you want:
x = rand(16, 64);
y = repmat(x, 1, 1, 2); % [16 x 64 x 2]
Jos (10584)
2018년 2월 15일
Maybe you're looking fo cell arrays, in which each cell can hold a vector of different lengths?
As an example:
Nrows = 10 ; % fixes
Ncolumns = randi(10,Nrows,1) ; % random lengths for each row
B = arrayfun(@(k) randi(10,1,k) , Ncolumns, 'un', 0)
% B{k} is a vector with Ncolumns(k) elements
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!