フィルターのクリア

In an assignment A(I) = B, the number of elements in B and I must be the same.

1 回表示 (過去 30 日間)
George
George 2013 年 2 月 17 日
Hello, I want to make 4 plots in one according to below:
R=8.3145;
n=1;
V=linspace(1,10,1000);
T=[100,200,300,400];
for i=1:4
P(i)=n*R*T(i)./ V;
hold on;
plot(V,P(i))
end
hold off;
I am getting the error above. If I do :
P=n*R*T(1)./V;
plot(V,P)
it's ok!I don't understand why the error.
Thank you!

採用された回答

Walter Roberson
Walter Roberson 2013 年 2 月 17 日
In your line
P(i)=n*R*T(i)./ V;
your n and R and T(i) are scalars, but your V is a vector, so the result is a vector. You are trying to store the vector into a scalar location P(i)
  2 件のコメント
George
George 2013 年 2 月 17 日
Oh yes!And I must just do "P=n*R*T(i)./ V;" and then "plot(V,P)". Is there a way to avoid loops in this situation?Also, if I want to place legend for these 4 different plots in one how can I do it given that it lies inside a loop?Thanks!
Walter Roberson
Walter Roberson 2013 年 2 月 17 日
[Tmat, Vmat] = meshgrid(T, V);
P = n .* R .* Tmat ./ Vmat;
plot(V, P)
You might need
plot(V, P')
instead.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by