T= 1:5:1000;
P=(10*(log(T/298))*T)+(12.41*T)+1550;
plot(T,P)
What's wrong with my code, why won't it run?

 채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 19일

0 개 추천

P = (10*(log(T/298)).*T) + (12.41*T) + 1550;
Note: the volunteers who answer questions are sensitive to spacing in code. As in when there isn't any, it is more difficult for the volunteers to understand the code and then they tend to wander off to answer questions that are easier to read.

댓글 수: 3

Morgan Sadler
Morgan Sadler 2015년 9월 19일
ok thanks do you know where I went wrong here?
Morgan Sadler
Morgan Sadler 2015년 9월 19일
It worked, thank you!!
Walter Roberson
Walter Roberson 2015년 9월 19일
T is a row vector 1 x 200, so log(T/298) is a row vector 1 x 200, so 10*(log(T/298)) is a row vector 1 x 200. You then had that "*" T. That is one row vector 1 x 200 "*" a row vector 1 x 200. But "*" is algebraic matrix multiplication. For matrix multiplication, the "inner dimensions" must be the same -- the second dimension of the left matrix must be the same as the first dimension of the right matrix. 1 x 200 by 1 x 200 does not satisfy that condition -- 200 ~= 1. So you get an error.
You could transpose the first matrix to be 200 x 1 using the .' operator, so that you were working with 200 x 1 by 1 x 200, if you wanted to get out a 200 x 200 matrix. Or you could transpose the second matrix to be 200 x 1, so that you were working with 1 x 200 by 200 x 1, if you wanted to get out a 1 x 1 matrix. Or you can switch to the element-by-element multiplication operator, .* instead of the matrix multiplication operator * and that is what I changed your code to.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2015년 9월 19일

댓글:

2015년 9월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by