Inverse of a cell array
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
the cyclist
2021 年 7 月 6 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!