Plotting arrays with different sizes

1 次查看(过去 30 天)
I want to plot a function where the arrays are different sizes
gamma = [1, 1.2, 1.4, 1.6, 1.8, 2];
x = [0:0.01:2000];
b = 349.22567;
y = 2.*(gamma.^2 - x./b);
Arrays have incompatible sizes for this operation.
How can I do this? Obviously
arrays have incopatible sizes
so this will not work. It would be unwise at best to do
plot(x, 2.*(gamma(1)^2 - x./b), 'b')
% etc...

采纳的回答

Star Strider
Star Strider 2023-5-26
编辑:Star Strider 2023-5-26
Transpose ‘gamma’ to create a family of curves —
gamma = [1, 1.2, 1.4, 1.6, 1.8, 2];
x = [0:0.01:2000];
b = 349.22567;
y = 2.*(gamma(:).^2 - x./b)
y = 6×200001
2.0000 1.9999 1.9999 1.9998 1.9998 1.9997 1.9997 1.9996 1.9995 1.9995 1.9994 1.9994 1.9993 1.9993 1.9992 1.9991 1.9991 1.9990 1.9990 1.9989 1.9989 1.9988 1.9987 1.9987 1.9986 1.9986 1.9985 1.9985 1.9984 1.9983 2.8800 2.8799 2.8799 2.8798 2.8798 2.8797 2.8797 2.8796 2.8795 2.8795 2.8794 2.8794 2.8793 2.8793 2.8792 2.8791 2.8791 2.8790 2.8790 2.8789 2.8789 2.8788 2.8787 2.8787 2.8786 2.8786 2.8785 2.8785 2.8784 2.8783 3.9200 3.9199 3.9199 3.9198 3.9198 3.9197 3.9197 3.9196 3.9195 3.9195 3.9194 3.9194 3.9193 3.9193 3.9192 3.9191 3.9191 3.9190 3.9190 3.9189 3.9189 3.9188 3.9187 3.9187 3.9186 3.9186 3.9185 3.9185 3.9184 3.9183 5.1200 5.1199 5.1199 5.1198 5.1198 5.1197 5.1197 5.1196 5.1195 5.1195 5.1194 5.1194 5.1193 5.1193 5.1192 5.1191 5.1191 5.1190 5.1190 5.1189 5.1189 5.1188 5.1187 5.1187 5.1186 5.1186 5.1185 5.1185 5.1184 5.1183 6.4800 6.4799 6.4799 6.4798 6.4798 6.4797 6.4797 6.4796 6.4795 6.4795 6.4794 6.4794 6.4793 6.4793 6.4792 6.4791 6.4791 6.4790 6.4790 6.4789 6.4789 6.4788 6.4787 6.4787 6.4786 6.4786 6.4785 6.4785 6.4784 6.4783 8.0000 7.9999 7.9999 7.9998 7.9998 7.9997 7.9997 7.9996 7.9995 7.9995 7.9994 7.9994 7.9993 7.9993 7.9992 7.9991 7.9991 7.9990 7.9990 7.9989 7.9989 7.9988 7.9987 7.9987 7.9986 7.9986 7.9985 7.9985 7.9984 7.9983
figure
plot(x, y)
grid
xlabel('X')
ylabel('Y')
legend("\gamma = "+string(gamma(:)), 'Location','best')
A slightly different version —
gamma = [1, 1.2, 1.4, 1.6, 1.8, 2].';
x = [0:0.01:2000];
b = 349.22567;
y = 2.*(gamma.^2 - x./b)
y = 6×200001
2.0000 1.9999 1.9999 1.9998 1.9998 1.9997 1.9997 1.9996 1.9995 1.9995 1.9994 1.9994 1.9993 1.9993 1.9992 1.9991 1.9991 1.9990 1.9990 1.9989 1.9989 1.9988 1.9987 1.9987 1.9986 1.9986 1.9985 1.9985 1.9984 1.9983 2.8800 2.8799 2.8799 2.8798 2.8798 2.8797 2.8797 2.8796 2.8795 2.8795 2.8794 2.8794 2.8793 2.8793 2.8792 2.8791 2.8791 2.8790 2.8790 2.8789 2.8789 2.8788 2.8787 2.8787 2.8786 2.8786 2.8785 2.8785 2.8784 2.8783 3.9200 3.9199 3.9199 3.9198 3.9198 3.9197 3.9197 3.9196 3.9195 3.9195 3.9194 3.9194 3.9193 3.9193 3.9192 3.9191 3.9191 3.9190 3.9190 3.9189 3.9189 3.9188 3.9187 3.9187 3.9186 3.9186 3.9185 3.9185 3.9184 3.9183 5.1200 5.1199 5.1199 5.1198 5.1198 5.1197 5.1197 5.1196 5.1195 5.1195 5.1194 5.1194 5.1193 5.1193 5.1192 5.1191 5.1191 5.1190 5.1190 5.1189 5.1189 5.1188 5.1187 5.1187 5.1186 5.1186 5.1185 5.1185 5.1184 5.1183 6.4800 6.4799 6.4799 6.4798 6.4798 6.4797 6.4797 6.4796 6.4795 6.4795 6.4794 6.4794 6.4793 6.4793 6.4792 6.4791 6.4791 6.4790 6.4790 6.4789 6.4789 6.4788 6.4787 6.4787 6.4786 6.4786 6.4785 6.4785 6.4784 6.4783 8.0000 7.9999 7.9999 7.9998 7.9998 7.9997 7.9997 7.9996 7.9995 7.9995 7.9994 7.9994 7.9993 7.9993 7.9992 7.9991 7.9991 7.9990 7.9990 7.9989 7.9989 7.9988 7.9987 7.9987 7.9986 7.9986 7.9985 7.9985 7.9984 7.9983
figure
plot(x, y)
grid
xlabel('X')
ylabel('Y')
legend("\gamma = "+string(gamma), 'Location','best')
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Gamma Functions 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by