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?

 採用された回答

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 ExchangeLog Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by