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

조회 수: 3 (최근 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
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dipole Antennas에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by