Mapping Out and Multiplying Elements in Vectors
조회 수: 3 (최근 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에서 Financial Toolbox에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!