deleting and adapting columns in matrix of function handles
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
If you a matrix that contains function handles, so for example:
A = @(x) [x , x^2, x^3; 2*x, 2*x^2, 2*x^3]
How can I delete/adapt the second column of A ?
0 comentarios
Respuestas (1)
dpb
el 29 de Nov. de 2015
There are no "columns" in A and A is not a matrix...
>> A = @(x) [x , x^2, x^3; 2*x, 2*x^2, 2*x^3]
A =
@(x)[x,x^2,x^3;2*x,2*x^2,2*x^3]
>> whos A
Name Size Bytes Class Attributes
A 1x1 16 function_handle
>> func2str(A)
ans =
@(x)[x,x^2,x^3;2*x,2*x^2,2*x^3]
>> whos ans
Name Size Bytes Class Attributes
ans 1x31 62 char
>>
As shown, A is a single function handle despite it defining a function that returns a 2D matrix when executed.
You either create a new function handle as desired or, in a more roundabout way, convert to a string representation and edit on the string and then redefine the handle from that new string via func2str
You can, of course, create an array of function handles and treat each element within as the above single handle and rewrite individual elements inside such. NB: however, they must be cell arrays.
>> B=[@(x) 1, @(x) x, @(x) x^2]
Error using horzcat
Nonscalar arrays of function handles are not allowed; use cell arrays instead.
>> B={@(x) 1, @(x) x, @(x) x^2}
B =
@(x)1 @(x)x @(x)x^2
>> whos B
Name Size Bytes Class Attributes
B 1x3 228 cell
>>
Also note, now the array is simply a cell array, just so happens the cell content is a set of function handles.
0 comentarios
Ver también
Categorías
Más información sobre Multidimensional Arrays en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!