colorbar not working?

4 visualizaciones (últimos 30 días)
sxh
sxh el 8 de En. de 2024
Movida: Dyuman Joshi el 9 de En. de 2024
clc;
close all;
clear;
x = -1:2/511:1;
[X,Y] = meshgrid(x);
R = sqrt(X.^2 + Y.^2);
Phi = atan2(X,Y);
Z = zeros(512,512);
index1 = find(Phi<pi/20 & Phi>-pi/20);
Z(index1)=6;
index2 = find(R<0.0142);
Z(index2)=50;
index3 = find(R>0.425);
Z(index3)=0;
surf(X,Y,Z)
colorbar
%view(2)
Any idea why the plot comes up all black?
Thanks
S
  2 comentarios
Dyuman Joshi
Dyuman Joshi el 8 de En. de 2024
Movida: Dyuman Joshi el 9 de En. de 2024
"Any idea why the plot comes up all black?"
Because your mesh is extremely dense. I have increased the mesh density by 5 times, so to can see the corresponding result.
However, if you want a refined surface/mesh, you can hide the grid lines, as @Voss has shown.
Also, note that you should not hard code values, as that is likely to cause issues - In this case while defining Z. And you can use logical indexing instead of find(), as it is more efficient.
x = -1:2*5/511:1;
[X,Y] = meshgrid(x);
R = sqrt(X.^2 + Y.^2);
Phi = atan2(X,Y);
%Define Z according to the size of R, instead of hard-coding
Z = zeros(size(R));
%logical indexing
index1 = (Phi<pi/20 & Phi>-pi/20);
Z(index1)=6;
index2 = (R<0.0142);
Z(index2)=50;
index3 = (R>0.425);
Z(index3)=0;
surf(X,Y,Z)
colorbar
%view(2)
sxh
sxh el 8 de En. de 2024
Movida: Dyuman Joshi el 9 de En. de 2024
Mesh density is not the problem here..
Thanks for the answer tho :)

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 8 de En. de 2024
The black you see is grid lines of the surface. You can turn them off by setting the surface EdgeColor property to 'none'.
clc;
close all;
clear;
x = -1:2/511:1;
[X,Y] = meshgrid(x);
R = sqrt(X.^2 + Y.^2);
Phi = atan2(X,Y);
Z = zeros(512,512);
index1 = find(Phi<pi/20 & Phi>-pi/20);
Z(index1)=6;
index2 = find(R<0.0142);
Z(index2)=50;
index3 = find(R>0.425);
Z(index3)=0;
surf(X,Y,Z,'EdgeColor','none')
colorbar
% view(2)

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by