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.

回答(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