Raise elements of cell arrays in the power of 2
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
gsourop
el 18 de Nov. de 2016
Comentada: Jay shankar Nanda
el 29 de Mzo. de 2021
Hi everyone,
I have a cell array A of 2x100, where each element is a scalar and I want to raise in the power of 2. I have tried:
for k=1:2;
for t=1:100;
A2{k,t}=A{k,t}.^2;
end;
end;
But it doesn't work. Thanks in advance.
2 comentarios
Jay shankar Nanda
el 29 de Mzo. de 2021
x={2,3,4};
>> x(2).^2
Undefined operator '.^' for input arguments of type 'cell'.
kindly tell how to access the input argumentand raise it to power
Respuesta aceptada
James Tursa
el 18 de Nov. de 2016
Editada: James Tursa
el 18 de Nov. de 2016
Like this?
A = 2x100 cell array of scalars
A2 = mat2cell(cellfun(@(x)x.^2,A),ones(1,2),ones(1,100));
SIDE NOTE:
Your posts seem to indicate that you have a lot of scalar data in cell arrays that you want to do basic matrix arithmetic/functions with. Is there a reason you have this data in cell arrays rather than double matrices? It would be a lot easier (and cleaner) to maintain this data as double matrices in your code rather than in cell arrays unless you have some specific reason to have the cell arrays.
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Matrices and Arrays 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!