Hello, i receive this error, i am attempting to plot Td with sample h
13 ビュー (過去 30 日間)
古いコメントを表示
here h is sample and p1, p2 is probability when i try plot Td compaing to sample value it indicates this error message
0 件のコメント
回答 (2 件)
Shivam Lahoti
2024 年 11 月 11 日 17:33
Hello,
The error "Matrix dimensions must agree" suggests a mismatch in the dimensions of the arrays you're working with. In your code, h is a vector with 11 elements, while n is a vector with 6 elements. This discrepancy can lead to issues when performing element-wise operations.
Ensure that all vectors involved (h, p1, p2, pl) have compatible dimensions for element-wise operations like .* and .^. If p1, p2, and pl are scalars, the operations should work correctly. However, if they are vectors, make sure their dimensions match those of h or can be broadcasted appropriately.
Adjust your calculations to ensure that all operations occur between arrays of compatible sizes. This should help resolve the error you're encountering when plotting Td against the sample h.
Regards,
Shivam
1 件のコメント
Walter Roberson
2024 年 11 月 11 日 18:05
If p1 and p2 are scalars, then the right hand side of the h.*EXPRESSION should be calculated correctly. However, it would be calculated to be the same size as n, a vector of length 6. It would be an error to .* together h (a vector 1 x 11) and something the same size as n, 1 x 6.
Voss
2024 年 11 月 12 日 16:35
h = 0:10;
n = 1:6;
p1 = 0.4;
p2 = 0.6;
Perhaps you meant
Td = h.'.*((1-p1.^n-p2.*p1.^n))./(p2.*p1.^n)
plot(h,Td)
Or
Td = h.*((1-p1.^n.'-p2.*p1.^n.'))./(p2.*p1.^n.')
plot(h,Td)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!