fplot: Attempted to access x(2); index out of bounds because numel(x)=1.

5 ビュー (過去 30 日間)
Devdatt Thengdi
Devdatt Thengdi 2018 年 3 月 16 日
コメント済み: Torsten 2018 年 3 月 19 日
Consider plot function.
B = arrayfun(@(x)Lobo(x(1), x(2), x(3), x(4), x(5), x(6)), x(1), 'un',0);
fplot(B, [0.01 0.2]);
Error:
Attempted to access x(2); index out of bounds because numel(x)=1.
  7 件のコメント
Walter Roberson
Walter Roberson 2018 年 3 月 16 日
Plotting Lobo with respect to all 5 variables would require a 6 dimensional plot. In my experience, 5 dimensions is the maximum you can encode and still have a semi-understandable ranking.
Devdatt Thengdi
Devdatt Thengdi 2018 年 3 月 16 日
Also, before plotting I am optimizing the same function. Now, in this line:
qfuel = THD/Ef;%Heat released by fuel Kw
I've observed that optimized values of x(1) to x(5) vary with Ef. How can I plot the 'optimized values' vs Ef (or vice versa)?

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

採用された回答

Walter Roberson
Walter Roberson 2018 年 3 月 16 日
You wrote
B = arrayfun(@(x)Lobo(x(1), x(2), x(3), x(4), x(5), x(6)), x(1), 'un',0);
Break this down:
Array_to_operate_over = x(1);
Function_to_call = @(x)Lobo(x(1), x(2), x(3), x(4), x(5), x(6));
B = arrayfun(Function_to_call, Array_to_operate_over, 'un', 0);
This requires that a vector or array x existed before the B = statement that you coded. The first element of that vector or array is extracted because of your x(1); and a function is executed for each member of that scalar because of the arrayfun(). The function you are calling tries to extract 6 elements from the scalar and pass the 6 of them into Lobo, but a scalar only has 1 elements so you get an index out of range error.
arrayfun() always proceeds one element at a time, so even if you had passed an array in, instead of the scalar x(1), then what would reach the Function_to_call would always be a scalar.
If somehow it all worked, then because of the 'un', 0 you would be returning a cell array of values. But you then proceed to try to fplot() that cell array of values, which is not possible.
  8 件のコメント
Devdatt Thengdi
Devdatt Thengdi 2018 年 3 月 16 日
So, if want to plot it against the first variable only,
plot(Ef, Xmat(i:1));
right?
Thanks man.
Torsten
Torsten 2018 年 3 月 19 日
plot(Ef, Xmat(:,1));

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDipole Antennas についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by