フィルターのクリア

colorbar not working?

3 ビュー (過去 30 日間)
sxh
sxh 2024 年 1 月 8 日
移動済み: Dyuman Joshi 2024 年 1 月 9 日
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 件のコメント
Dyuman Joshi
Dyuman Joshi 2024 年 1 月 8 日
移動済み: Dyuman Joshi 2024 年 1 月 9 日
"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 2024 年 1 月 8 日
移動済み: Dyuman Joshi 2024 年 1 月 9 日
Mesh density is not the problem here..
Thanks for the answer tho :)

サインインしてコメントする。

採用された回答

Voss
Voss 2024 年 1 月 8 日
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)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRed についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by