Mapping Out and Multiplying Elements in Vectors
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have three matrices:
Price:
[ 24 29 55;
30 40 56;
19 33 62 ]
Volume:
[100 350 222;
290 300 234;
80 219 180 ]
Grades:
[1 2 3;
1 2 3;
2 3 2 ]
A Column Vector with Stock Symbols:
[ ABX CDF TTQ ]
A Row Vector with Dates:
[040116;
040116;
040216]
I need to calculate the average trading prices of certain securities grouped by their respective grade (which may vary over time). The output I am attempting to create is similar to:
[ 1 2 3 ]
[040116; [28.46 34.08 55.51;
040216] 0.00 48.77 33.00]
I am a Python/SAS developer recently assigned to a MATLAB project so I am new to the language. Any assistance would be greatly appreciated.
0 commentaires
Réponses (1)
Nikhil Vyas
le 26 Avr 2016
In your expected output matrix, where is the row [0.00 48.77 33.00] coming from?
For the price matrix, you can find the mean directly as following:
pr_mean = mean(Price);
This would return you a Row with the means of the three columns, which is the default behavior.
In case you wanted to find the mean of the Rows, you could do this:
pr_mean_c = mean(Price');
Now, to use the Obtained rows in the output matrix specified by you, you can use the matrix concatenation operations.
To extract certain rows and columns from a matrix, go through the following link:
Once you have the rows / columns you require, it's just a matter of concatenating them. For this, I strongly suggest you go through the following documentation link:
Just remember: ',' to concatenate horizontally and ';' to concatenate vertically. :)
1 commentaire
Voir également
Catégories
En savoir plus sur Transaction Cost Analysis dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!