Hello, i receive this error, i am attempting to plot Td with sample h

조회 수: 13 (최근 30일)
Ted Erdenekhuyag
Ted Erdenekhuyag 2021년 12월 19일
답변: Voss 2024년 11월 12일 16:35
here h is sample and p1, p2 is probability when i try plot Td compaing to sample value it indicates this error message

답변 (2개)

Shivam Lahoti
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
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
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)
Td = 11×6
1.0e+03 * 0 0 0 0 0 0 0.0015 0.0077 0.0234 0.0624 0.1601 0.4042 0.0030 0.0155 0.0467 0.1249 0.3202 0.8085 0.0045 0.0232 0.0701 0.1873 0.4803 1.2127 0.0060 0.0310 0.0935 0.2497 0.6404 1.6169 0.0075 0.0387 0.1169 0.3122 0.8005 2.0212 0.0090 0.0465 0.1402 0.3746 0.9606 2.4254 0.0105 0.0542 0.1636 0.4371 1.1207 2.8296 0.0120 0.0620 0.1870 0.4995 1.2807 3.2339 0.0135 0.0697 0.2104 0.5619 1.4408 3.6381
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
plot(h,Td)
Or
Td = h.*((1-p1.^n.'-p2.*p1.^n.'))./(p2.*p1.^n.')
Td = 6×11
1.0e+03 * 0 0.0015 0.0030 0.0045 0.0060 0.0075 0.0090 0.0105 0.0120 0.0135 0.0150 0 0.0077 0.0155 0.0232 0.0310 0.0387 0.0465 0.0542 0.0620 0.0697 0.0775 0 0.0234 0.0467 0.0701 0.0935 0.1169 0.1402 0.1636 0.1870 0.2104 0.2337 0 0.0624 0.1249 0.1873 0.2497 0.3122 0.3746 0.4371 0.4995 0.5619 0.6244 0 0.1601 0.3202 0.4803 0.6404 0.8005 0.9606 1.1207 1.2807 1.4408 1.6009 0 0.4042 0.8085 1.2127 1.6169 2.0212 2.4254 2.8296 3.2339 3.6381 4.0423
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
plot(h,Td)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by