Error in line 2... Won't plot my graph.

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?

 采纳的回答

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 个评论

ok thanks do you know where I went wrong here?
It worked, thank you!!
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 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by