Inverse of a cell array
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MarshallSc
el 6 de Jul. de 2021
Respondida: the cyclist
el 6 de Jul. de 2021
Hello, I'm trying to get the inverse values of a 10*10 cell array, each containing a 4*4 matrix. The code is (credit to Stephen Cobeldick for the code):
x1 = rand(10,10);
y1 = rand(10,10);
z1 = rand(10,10);
r1 = rand(10,10);
a1 = cat(3,x1,y1,z1,r1);
x2 = rand(10,10);
y2 = rand(10,10);
z2 = rand(10,10);
r2 = rand(10,10);
a2 = cat(4,x2,y2,z2,r2);
tmp = num2cell(sqrt(a1./a2),3:4);
fun = @(a)reshape(a,4,4);
out = cellfun(fun,tmp,'uni',0);
Now I want the inverse of the results (1/values). I used some commands but the results are not accurate. For example using:
out2=cellfun(@inv, out, 'uniform', 0);
But the results are not correct. Is there any method that can calculate the inverse of the cell array? Thank you.
0 comentarios
Respuesta aceptada
the cyclist
el 6 de Jul. de 2021
Do you mean you want the reciprocal of each element of each matrix? (That is not what the inverse of a matrix means.)
If so, then you want
x1 = rand(10,10);
y1 = rand(10,10);
z1 = rand(10,10);
r1 = rand(10,10);
a1 = cat(3,x1,y1,z1,r1);
x2 = rand(10,10);
y2 = rand(10,10);
z2 = rand(10,10);
r2 = rand(10,10);
a2 = cat(4,x2,y2,z2,r2);
tmp = num2cell(sqrt(a1./a2),3:4);
fun = @(a)reshape(a,4,4);
out = cellfun(fun,tmp,'uni',0);
out2=cellfun(@(x) 1./x, out, 'uniform', 0);
% example of one reciprocal:
out{1}
out2{1}
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!