Gradient using cells and functions
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Spyros Polychronopoulos
am 11 Dez. 2017
Bearbeitet: Spyros Polychronopoulos
am 11 Dez. 2017
I am taking the gradient of a structure array in x,y as shown below part_x1 and part_y1:
for k1=1:10
q1(k1).p=rand(10,10);
end
for k1=1:10
[part_x1(k1).p,part_y1(k1).p]= gradient(q1(k1).p); %gradient
end
Now with function handle I am trying to do the same as above but doesn't work
A=rand(10^3,1);
for k2=1:10^3
a{k2}=@(z) z*A(k2);
end
%preparing the array for the gradient
l=1;
for k3=1:10
for k4=1:10
for k5=1:10
q2(k3).p{k4,k5}=@(z) a{l}(z);
l=l+1;
end
end
end
clear k1 k2 k3 k4 k5 l
% now I want to do what I have done with the matrix above but I have functions this returns 1 value so doesn't work
for k1=1:10
[part_x2{k1}.p,part_y2{k1}.p]=@(z) (cellfun(@gradient,q2(k1).p(z)));
end
%this doesn't work either
for k1=1:10^3
[part_x2{k1}.p,part_y2{k1}.p]=arrayfun(@(z) gradient(q2(k1).p(z)));
end
Any ideas? Thank you!
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!