Trying to plot x,y, but it says error in y = f(x);

3 次查看(过去 30 天)
function graph
x = 1:100;
y = f(x);
plot(x,y);
end
function [y] = f(n)
y = n * log2(n);
end

采纳的回答

Star Strider
Star Strider 2016-3-17
You need to use element-wise operations in this line:
y = n .* log2(n);
Note the ‘.*’ replacing the ‘*’. See the documentation for Array vs. Matrix Operations for details.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by