Assign value in a cell with a "oneliner"

1 visualización (últimos 30 días)
Florian Levy
Florian Levy el 9 de Ag. de 2019
Comentada: Florian Levy el 9 de Ag. de 2019
Hello Matlab folks,
I am trying to retrieve a cell and change some of its values with only one command line.
I have today :
>> x = {'a';'b';'c';'d';'e'};
>> x{2} = 'y';x{4} = 'z';
I am looking for something like:
>> UnknownFunction({'a';'b';'c';'d';'e'},2,'x',4,'z');
And because it is not funny otherwise, I can't create an UnknownFunction.m myself as I need to use only native Matlab function.
Any Idea ?
Thanks

Respuesta aceptada

madhan ravi
madhan ravi el 9 de Ag. de 2019
[x{2},x{4}]=deal('x','z')
  4 comentarios
madhan ravi
madhan ravi el 9 de Ag. de 2019
Editada: madhan ravi el 9 de Ag. de 2019
Thanks dpb , I thought so too until the OP commented xd:
subsref({'a';'b';'c';'d';'e'},substruct('{}',{2}))
% or you can use the below ones if the user made anonymous function is allowed
retriever = @(x,y) x(y);
% ^_^ - use {} if you want
retriever({'a';'b';'c';'d';'e'},2)
Florian Levy
Florian Levy el 9 de Ag. de 2019
I actually just found the function that suits my need.
getcolumn({'a';'b';'c';'d';'e'}',[2 4])
Thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by