Dividing a Matrix with a column vector (Inside a Loop)
3 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone.
I am having a problem doing a matrix by vector division. The matrices and vectors are here attached.
I am in a loop
for i=1:N N=10000
for t=1:T T=4
and q_i is (TXN), p_i is (TXN) and P is (1XT).
The exact operation is q_i(t,i)=p_i(t,i)./P(t).
Doing this operation the outcome is the matrix q_i attached above.
The problem is that I don't want that the matrix q_i has the same numbers in each cell. What I want is that each element in the row of the matrix p_i is divided by the P element in the relative row(e.g: The first element of P divides all the 10000 columns of p_i in the first row by itself) . If you do this operation not of in a loop, the result would be correct. Giving a matrix q_i that has the same values within the column and different between columns(As the matrix p_i). I would like to obtain the matrix q_i's with cells equal within the column and different between.
Thanks for the availability
0 件のコメント
回答 (1 件)
Cris LaPierre
2021 年 1 月 29 日
First, the syntax of your for loops is incorrect. Declare N and T before writing the for loops. See the examples on this page.
N=10000;
T=4;
for i=1:N
for t=1:T
end
end
Perhaps more is going on in your code than what you've shared? I get the same result whether I use for loops or elementwise array division. However, the values I get do not match what you have in the q_i variable you have shared.
% manual calculation
p_i(1,1)/P(1)
ans = 6.0098
% for loop result
myq_i(1,1)
ans = 6.0098
% your value
q_i(1,1)
ans = 6.3096
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!