Error Using cellfun for a Matrix
1 回表示 (過去 30 日間)
古いコメントを表示
I have an 81 x 81 matrix that divided it into smaller matrices:
a = rand(81,81);
n = 3*ones(1,27);
a_d = mat2cell(a,n,n)
Now I want to perform this operation on each of the small matrices but it gives me error:
G_x = @(x) sum((x-a_d)./(x+a_d),'all');
B_x = cellfun(G_x,a_d)
Can someone please help me! Thank you.
0 件のコメント
採用された回答
Simon Chan
2022 年 1 月 10 日
Try the following:
for r = 1:27
for c = 1:27
A = a_d{r,c};
B_x{r,c} = cellfun(@(x) sum((x-A)./(x+A),'all'),num2cell(A));
end
end
0 件のコメント
その他の回答 (1 件)
Kevin Holly
2022 年 1 月 10 日
a = rand(81,81);
n = 3*ones(1,27);
a_d = mat2cell(a,n,n);
for i = 1:27
for j = 1:27
G_x = @(x) sum((x-a_d{i,j})./(x+a_d{i,j}),'all');
B_x(i,j,:,:) = cellfun(G_x,a_d);
end
end
size(B_x)
2 件のコメント
Kevin Holly
2022 年 1 月 10 日
編集済み: Kevin Holly
2022 年 1 月 10 日
FYI, braces needed to be added as Simon had done.
a = rand(81,81);
n = 3*ones(1,27);
a_d = mat2cell(a,n,n);
for i = 1:27
for j = 1:27
G_x = @(x) sum((x-a_d{i,j})./(x+a_d{i,j}),'all');
B_x{i,j,:,:} = cellfun(G_x,a_d); %Added braces here
end
end
size(B_x)
参考
カテゴリ
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!