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

1 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by