fplot: Attempted to access x(2); index out of bounds because numel(x)=1.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Devdatt Thengdi
el 16 de Mzo. de 2018
Comentada: Torsten
el 19 de Mzo. de 2018
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 comentarios
Walter Roberson
el 16 de Mzo. de 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.
Respuesta aceptada
Walter Roberson
el 16 de Mzo. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Bounding Regions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!