Graphics from 2D data
9 views (last 30 days)
Show older comments
Hi there,
I have a matrix x of size 39505X2 and i was wondering how can i plot graphics as shown below from my data

0 Comments
Accepted Answer
Star Strider
on 26 Sep 2023
It would be nice to have ‘x’ since I suspect that ‘x(:,1)’ cycliically repeats. Using reshape to use the cyclic repeat information to create a matrix from ‘x(:,2)’ could be the solution.
8 Comments
Star Strider
on 29 Sep 2023
Edited: Star Strider
on 29 Sep 2023
As always, my pleasure!
EDIT — (29 Sep 2023 at 17:48)
Just out of interest —
LD = load('x y data.mat');
Data = LD.all_data;
x = Data(:,1);
y = Data(:,2);
zfcn = @(b,xy) b(1).*exp(-(xy(:,:,1)-b(2)).^2*b(3)) .* exp(-(xy(:,:,2)-b(4)).^2*b(5));
[N,C] = hist3(Data,[250 250]);
xv = linspace(min(x), max(x), size(N,1));
yv = linspace(min(y), max(y), size(N,2));
[X,Y] = ndgrid(xv, yv);
XY = cat(3, X, Y);
B = lsqcurvefit(zfcn,[50,mean(x),300,mean(y),300],XY,N)
ZZ = zfcn(B,XY);
figure
surf(X, Y, N, 'EdgeColor',[1 1 1]*0.5, 'FaceAlpha',0.25, 'EdgeAlpha',0.25)
hold on
surf(X,Y,ZZ, 'EdgeColor','interp')
hold off
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
.
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







