generate a random matrix with constraints

2 visualizaciones (últimos 30 días)
vachelard
vachelard el 4 de Abr. de 2014
Comentada: vachelard el 5 de Abr. de 2014
hello,
I break a question about a problem I have to solve but I do not know if what I want to do is possible. I have a matrix (193.1) I will call A, is a column vector. I want to generate a matrix (193.3) or the sum of line 1 is equal to the value of A (1,1). the values taken by A are between 0.5 and -0.5, it's continues values. My matrix A does not always have the same value or complexity of the problem. If someone has an idea that would help me a lot. Thank you.

Respuesta aceptada

Walter Roberson
Walter Roberson el 4 de Abr. de 2014
  12 comentarios
Image Analyst
Image Analyst el 5 de Abr. de 2014
You are missing a comma after (m-1)] and before the n. Try it like this:
index = p + repmat ([0: n: n * (m-1)], n, 1)
x = (b-a) * x (index) + a; % Switches & rescale x
Now that will also bomb if index is some fractional number, a negative number, or zero, so be sure you know what indexes you ever might expect to get.
vachelard
vachelard el 5 de Abr. de 2014
just to be sure I get the correct code. Rhedgefund = Y (:, 1);
cols_to_generate = 3;
for K = 1: length (Y)
    Neva (K, :) = randfixedsum (1 cols_to_generate, Y (K), -0.15, 0.15);
end
or Y is my data matrix 193 * 1 which is my target matrix.

Iniciar sesión para comentar.

Más respuestas (1)

vachelard
vachelard el 4 de Abr. de 2014
Your two answers are good but not exactly give me the desired result. I'll try to explain better.
I expected returns monthly for 15 years. I try to generated a matrix whose sum line by line give me the monthly return of my base matrix. Knowing the values of my matrix generated can be negative. I tried this code but the values are just positive: mat = rand(193, 3); rowsum = sum(mat,2); mat = bsxfun(@rdivide, mat, rowsum);

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by