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
조회 수: 13 (최근 30일)
이전 댓글 표시
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.
채택된 답변
Star Strider
2023년 2월 7일
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
추가 답변 (1개)
Voss
2023년 2월 7일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Particle Swarm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!