フィルターのクリア

Can you make this source accept a variable declaration

1 回表示 (過去 30 日間)
Isaiah Slemons
Isaiah Slemons 2019 年 5 月 30 日
回答済み: Walter Roberson 2019 年 5 月 30 日
I'm using a community add-on called scatterbar3 and I need to be able to call it a variable but the way the source is written it's currently unable to do that. Thanks in advance.
Source:
function scatterbar3(X,Y,Z,width) % Original
% function var = scatterbar3(X,Y,Z,width) What I'd like to be able to do.
[r,c]=size(Z);
for j=1:r,
for k=1:c,
if ~isnan(Z(j,k))
drawbar(X(j,k),Y(j,k),Z(j,k),width/2)
end
end
end
zlim=[min(Z(:)) max(Z(:))];
if zlim(1)>0,zlim(1)=0;end
if zlim(2)<0,zlim(2)=0;end
axis([min(X(:))-width max(X(:))+width min(Y(:))-width max(Y(:))+width zlim])
caxis([0 50])
function drawbar(x,y,z,width)
h(1)=patch([-width -width width width]+x,[-width width width -width]+y,[0 0 0 0],'b');
h(2)=patch(width.*[-1 -1 1 1]+x,width.*[-1 -1 -1 -1]+y,z.*[0 1 1 0],'b');
h(3)=patch(width.*[-1 -1 -1 -1]+x,width.*[-1 -1 1 1]+y,z.*[0 1 1 0],'b');
h(4)=patch([-width -width width width]+x,[-width width width -width]+y,[z z z z],'b');
h(5)=patch(width.*[-1 -1 1 1]+x,width.*[1 1 1 1]+y,z.*[0 1 1 0],'b');
h(6)=patch(width.*[1 1 1 1]+x,width.*[-1 -1 1 1]+y,z.*[0 1 1 0],'b');
set(h,'facecolor','flat','FaceVertexCData',z)
  2 件のコメント
dpb
dpb 2019 年 5 月 30 日
編集済み: dpb 2019 年 5 月 30 日
Well, what do you want it to return? You can have it return whatever you want but it's your call as to what that should be.
What would you intend to do with the return value(s) if you had it(them)?
Isaiah Slemons
Isaiah Slemons 2019 年 5 月 30 日
I want it to return a variable to me that I can set to User Data inside of a struct. I basically want to be able to turn the bar plot on and off.

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

採用された回答

Walter Roberson
Walter Roberson 2019 年 5 月 30 日
function all_h = scatterbar3(X,Y,Z,width) % Original
[r,c]=size(Z);
all_h = gobjects(r, c, 6);
for j=1:r,
for k=1:c,
if ~isnan(Z(j,k))
all_h(j, k, :) = drawbar(X(j,k),Y(j,k),Z(j,k),width/2)
end
end
end
zlim=[min(Z(:)) max(Z(:))];
if zlim(1)>0,zlim(1)=0;end
if zlim(2)<0,zlim(2)=0;end
axis([min(X(:))-width max(X(:))+width min(Y(:))-width max(Y(:))+width zlim])
caxis([0 50])
function h = drawbar(x,y,z,width)
h(1)=patch([-width -width width width]+x,[-width width width -width]+y,[0 0 0 0],'b');
h(2)=patch(width.*[-1 -1 1 1]+x,width.*[-1 -1 -1 -1]+y,z.*[0 1 1 0],'b');
h(3)=patch(width.*[-1 -1 -1 -1]+x,width.*[-1 -1 1 1]+y,z.*[0 1 1 0],'b');
h(4)=patch([-width -width width width]+x,[-width width width -width]+y,[z z z z],'b');
h(5)=patch(width.*[-1 -1 1 1]+x,width.*[1 1 1 1]+y,z.*[0 1 1 0],'b');
h(6)=patch(width.*[1 1 1 1]+x,width.*[-1 -1 1 1]+y,z.*[0 1 1 0],'b');
set(h,'facecolor','flat','FaceVertexCData',z)
However, since you do not draw bars for nan values, there will be locations where the placeholder graphics objects will not be overwritten with patch objects, so you cannot just blindly set(all_h, 'visible', 'off')
Note that the code is inefficient and should ideally only draw a single patch object per invocation of drawbar.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by