both @Voss and @Star Strider answer perfectly my question. I think that for this project i'll go for the mesh instead of the surf due to it's primitive chart properties so that's why i accepted the mesh answer and not the surf one.
mesh or surf from x y z coordinates
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Luca Ferro
am 7 Feb. 2023
Kommentiert: Luca Ferro
am 8 Feb. 2023
I'm not experienced at all with meshes or 3d plotting, please be patient.
I have a firefly algorithm that optimizes pid paramters given a transfer function.
I would like to visualize how the swarm moves through the iterations, i tried with scatter3 and it works decently still i would prefer a better visualization so i'm trying to understand if surf and/or mesh are viable options.
The output data of the swarm is in the swarm.mat file, basically a nested cell array where the each cell represents a firefly has 2 nested cells, one with coordinates (the 3 pid parameters) and one with fitness evaluation:
{1×2 cell} -> {[35.3854 38.5853 45.3113]} {[0.0910]}
i would like to create a mesh out of the coordinates, first statically from the .mat i'm sharing, then i'll loop it on my own for each iteration creating a gif (already did it with the scatter version).
Is creating a mesh something doable with the data i have? if so, i would really appreciated some hints.
2 Kommentare
Akzeptierte Antwort
Star Strider
am 7 Feb. 2023
I am not certain what you want.
One approach —
LD = load(websave('swarm','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1287560/swarm.mat'))
% ANS = LD.ans
xyz = cell2mat(cat(1,LD.ans{:})) % Create MAtrix From Cell Arrays
xv = linspace(min(xyz(:,1)), max(xyz(:,1)), size(xyz,1)); % Linear Vector For Interpolation
yv = linspace(min(xyz(:,2)), max(xyz(:,2)), size(xyz,1)); % Linear Vector For Interpolation
[X,Y] = ndgrid(xv, yv); % Create Grid Matrices
F = scatteredInterpolant(xyz(:,1), xyz(:,2), xyz(:,3)); % Create Interpolation Function
Z = F(X,Y); % Interpolate
figure
surfc(X, Y, Z)
xlabel('X')
ylabel('Y')
zlabel('Z')
colormap(turbo)
colorbar
view(-60,25)
.
0 Kommentare
Weitere Antworten (1)
Voss
am 7 Feb. 2023
Maybe something like this:
load swarm
data = vertcat(f{:});
data = cell2mat(data(:,1))
I = scatteredInterpolant(data(:,[1 2]),data(:,3));
[pid1,pid2] = meshgrid(unique(data(:,1)),unique(data(:,2)));
surf(pid1,pid2,I(pid1,pid2))
0 Kommentare
Siehe auch
Kategorien
Mehr zu Particle Swarm 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!