How to dynamically create multiple column vectors?
显示 更早的评论
Hi there. I need to compute a matrix R which is computed the following way.
STEP 1: Create L number of column vectors which contains M number of elements
STEP 2: Multiply each column vector by it's transpose, obtaining a MxM matrix
STEP 3: Find the sum of adding all the matrices found in step 2.
My questions are the following:
1) What is the best way to use a for loop to create the column vectors i need?
2) How do I take elements from the end of one array and add them to my new array? (see comment in code below)
M = 5; % Number or elements in each vector
L = 1000; % Number of column vectors
N = M+L;
a = 0.05;
x = cos(2*pi*0.2*(0:N-1)) + cos(2*pi*0.38*(0:N-1))+(a*randn(1,N));
d = 0.4*cos(2*pi*0.2*(0:N-1)) + (pi/5);
% Compute R
% STEP 1: Create L number of column vectors which contains M number of elements
% STEP 2: Multiply each column vector by it's transpose, obtaining a MxM
% matrix
% STEP 3: Find the sum of the matrices found in step 2.
% x0 = [x(1) x(end) x(end-1) x(end-2) x(end-3)].transpose
% x1 = [x(2) x(1) x(end) x(end-1) x(end-2)].transpose
% x2 = [x(3) x(2) x(1) x(end) x(end-1)].transpose
% x3 = [x(4) x(3) x(2) x(1) x(end)].transpose
% x4 = [[x(5) x(4) x(3) x(2) x(1)].transpose
% x(L-1) = [x(L) x(L-1) x(L-2) x(L-3) x(L-4)].
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!