i have a problem with my code and i dont know how solve this?
Mostrar comentarios más antiguos
I have a matrix of monthly returns I call Ynet (193.1) I'd like to build a matrix yields random I call randomR with an average yield of my one line is equal to the value of the row Ynet has.
Ynet example, if (1,1) = 0.23 I need the average randomR (1, :) is equal to 0.23.
Until then I got there, the problem comes from my values of my matrix randomR I need them to be between [-0.25, 0.25] gold mine that is not always the case. Over the size of my matrix randomR must be between 1 and 30 depending on the number of returns I want.
That is where I am:
simulation = -0.2 +0.4 * rand (193.5).;
rowsum = mean (simulation 2);
simulation bsxfun = (@ rdivide, simulation, rowsum);
for i = 1:5
randomR (:, i) = simulation (:, i) * Ynet,.
end
thank you
3 comentarios
Walter Roberson
el 5 de Abr. de 2014
The parameter to rand() is the array size to generate, not a floating point number.
vachelard
el 5 de Abr. de 2014
Image Analyst
el 5 de Abr. de 2014
I've read your post 6 times and I can't understand it. Like what does this mean: "I call Ynet (193.1)" What is 193.1? That can't be part of the variable name. We don't know how many more writing errors there might be, so it's best to attach your m-file with the paper clip icon, after you've put in a comment before each line about what that line is supposed to do.
Respuesta aceptada
Más respuestas (2)
Walter Roberson
el 5 de Abr. de 2014
mean(simulation, 2)
does not calculate a row sum. You would use sum(simulation, 2) for a row sum
Image Analyst
el 5 de Abr. de 2014
0 votos
Like I said, I can't figure out what you want. You say " I need them (randomR) to be between [-0.25, 0.25] gold mine that is not always the case. Over the size of my matrix randomR must be between 1 and 30". So which is it ? Do you need randomR values to be between -.25 and +.25, OR between 1 and 30?
6 comentarios
vachelard
el 5 de Abr. de 2014
Image Analyst
el 6 de Abr. de 2014
Why would it be either 1 or 30 columns wide? The simulation array is 8 columns wide, not 1 or 30, and you're looping over columns of simulation. randomR does not exist yet - you're creating it in the loop - so if course it will have 8 columns, not 1 or 30.
vachelard
el 6 de Abr. de 2014
Image Analyst
el 6 de Abr. de 2014
Sorry, I don't understand that. Does anyone else understand what was said?
vachelard
el 6 de Abr. de 2014
vachelard
el 6 de Abr. de 2014
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!