필터 지우기
필터 지우기

change the dimension of multidimensional matrix

조회 수: 1 (최근 30일)
ABDUL
ABDUL 2018년 2월 15일
댓글: Jan 2018년 2월 15일
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.

답변 (2개)

Jan
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
ABDUL
ABDUL 2018년 2월 15일
this is my code i am getting the error message as Error using .* Matrix dimensions must agree. Error in selected_mapping_mimo (line 58) p=[p; B_1(k,:).*ofdm_symbol(:,:,:)]; ofdm_symbol=randn(100,64,2)+(1j*randn(100,64,2));
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 p=[]; for k=1:C p=[p; b1(k,:).*ofdm_symbol(:,:,:)]; end
can any one help me in this code to debug it
Jan
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)
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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by