ERROR. "not enough input argument" when publishing on html (Line 2)

1 回表示 (過去 30 日間)
Oscar Serna
Oscar Serna 2016 年 10 月 8 日
コメント済み: Walter Roberson 2016 年 10 月 9 日
function [E]=Energy(x,y)
for n = 0:1:size(x)
E = sum(y.^2);
end
E;
stem(x,y), grid;
end
  2 件のコメント
KSSV
KSSV 2016 年 10 月 9 日
How did you run the file?
Walter Roberson
Walter Roberson 2016 年 10 月 9 日
The bit about "publish" is the key here: the publish operation needs to be told what values to use to run the code with.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 10 月 9 日
編集済み: Walter Roberson 2016 年 10 月 9 日
Note: your code is not good code.
First, size(x) is always a vector unless you specify the dimension. It is a mistake to use a vector as the endpoint of a colon operator. You should either specify the dimension or you should use length, such as 0:1:length(x)
Secondly, in every iteration of the for loop, you do exactly the same thing, and overwrite all of the output variable E . You do not use the loop control variable either, so the effect is as if you just waste some time and then do the assignment once. Your work to be done in the loop should depend upon which iteration you are doing, usually explicitly (but sometimes you are iterating using a variable on the right of the assignment and creating a new value of the variable on the left.)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by