Mapping Out and Multiplying Elements in Vectors
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Nikhil Vyas
2016-4-26
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. :)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Transaction Cost Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!