Inverse of a cell array
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MarshallSc
le 6 Juil 2021
Réponse apportée : the cyclist
le 6 Juil 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 commentaires
Réponse acceptée
the cyclist
le 6 Juil 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur ANOVA dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!