Can you make this source accept a variable declaration

1 次查看(过去 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 CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by