Error Using cellfun for a Matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
MarshallSc
el 10 de En. de 2022
Editada: Kevin Holly
el 10 de En. de 2022
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 comentarios
Respuesta aceptada
Simon Chan
el 10 de En. de 2022
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 comentarios
Más respuestas (1)
Kevin Holly
el 10 de En. de 2022
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 comentarios
Kevin Holly
el 10 de En. de 2022
Editada: Kevin Holly
el 10 de En. de 2022
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)
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!