Draw matrix with circle points
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Now I am working on some physics problem, and I need to obtaine scaled figure of dots as shown below:![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430363/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430363/image.jpeg)
This is 2D plot with dots of data scaled according to some parameter. Here is my try to calculate and build it:
clc
clear
Nx = 1024;
Ny = 1024;
L = 40;
x = linspace(-L/2,L/2, Nx); hx = x(3) - x(2);
x_int = x(2:end-1)';
y = linspace(-L/2, L/2, Ny); hy = y(3) - y(2);
y_int = y(2:end-1)';
% %1D second derivative in x
% ex = ones(length(x)-2, 1)/hx^2;
% d1d = (spdiags([ex, -2*ex, ex], [-1, 0, 1], length(ex), length(ex)));
% ey = ones(length(y)-2, 1)/hy^2;
% d1d = (spdiags([ey, -2*ey, ey], [-1, 0, 1], length(ey), length(ey)));
%1D second derivatives
ex = ones(length(x)-2, 1)/hx^2/12;
d1dx = (spdiags([-ex, 16*ex, -30*ex, 16*ex, -ex], -2:2, length(ex), length(ex)));
ey = ones(length(x)-2, 1)/hy^2/12;
d1dy = (spdiags([-ey, 16*ey, -30*ey, 16*ey, -ey], -2:2, length(ey), length(ey)));
%full second derivative matrix in 2D
Lxx = kron(eye(length(y)-2), d1dx);
Lyy = kron(d1dy, eye(length(x)-2));
[X,Y] = meshgrid(x(2:end-1), y(2:end-1));
N = 34; M = 55;
[TH,R] = cart2pol(X,Y);
R0 = 10;
delta = 0.35;
gamma = 0.02;
array_r = [0.01 0.05 0.1 0.15 0.2 0.25]; n = 5; w = 1;
IPR = NaN(6,120);
for i = 1:1:6
tic
delta_r = array_r(1,i);
V0 = - 12*(exp(-(R-R0*(1+delta_r*cos(N*TH)+delta_r*cos(M*TH))).^2/w^2) + exp(-(R+R0*(1+delta_r*cos(N*TH)+delta_r*cos(M*TH))).^2/w^2));
H = -0.5*(Lxx + Lyy) + spdiags(V0(:), 0, size(Lxx,1), size(Lxx, 2));
[V, D] = eigs(H, 120, -14);
D = diag(D);
[D, ind] = sort(D);
V = V(:,ind);
for j = 1:1:120
v = V(:,j);
v = reshape(v, length(x)-2, length(x)-2);
IPR(i,j) = trapz(x(2:end-1),trapz(x(2:end-1),(v.*conj(v)).^2,2))/(trapz(x(2:end-1),trapz(x(2:end-1),(v.*conj(v)),2))).^2;
end
toc
if i == 1
IPR_1 = IPR(i,:);
D_1 = D;
end
if i == 2
IPR_2 = IPR(i,:);
D_2 = D;
end
if i == 3
IPR_3 = IPR(i,:);
D_3 = D;
end
if i == 4
IPR_4 = IPR(i,:);
D_4 = D;
end
if i == 5
IPR_5 = IPR(i,:);
D_5 = D;
end
if i == 6
IPR_6 = IPR(i,:);
D_6 = D;
end
load gong
sound(2*y,1*Fs);
end
f1 = figure;
plot(IPR')
f2 = figure;
imagesc(array_r,D,IPR)
% V0 = - 12*(exp(-(R-R0*(1+delta_r*cos(N*TH)+delta_r*cos(M*TH))).^2/w^2) + exp(-(R+R0*(1+delta_r*cos(N*TH)+delta_r*cos(M*TH))).^2/w^2));
return
But as I read from documentation imagesc doesnt have parameter to make something in this manner. Also, my coding is awful, and using several if conditions hurts my eyes and limits me in changing number of i. Is there something I could do about it? Thanks in advance.
3 Kommentare
Mathieu NOE
am 10 Jul. 2023
try with scatter , use z to tune your circle's color
use 'filled' option if you want filled circles
pointsize = 15;
x = linspace(0,3*pi,200);
y = cos(x) + rand(1,200);
c = linspace(1,10,length(x));
scatter(x,y,pointsize,c,"filled")
Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Object Programming 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!