Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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 Kommentare
Walter Roberson
Walter Roberson am 16 Mär. 2018
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 am 16 Mär. 2018
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)?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 16 Mär. 2018
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 Kommentare
Devdatt Thengdi
Devdatt Thengdi am 16 Mär. 2018
So, if want to plot it against the first variable only,
plot(Ef, Xmat(i:1));
right?
Thanks man.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Audio Processing Algorithm Design finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by