Verfasst am: 25.10.2009, 21:37
Titel: Buttondownfcn bei patch
Hallo,
ich habe eine Funktion bei der die Werte einer Martix (diffmat) als eine Reihe von farbigen Patches ausgegeben werden. Nun muss ich die Funktion so erweitern, dass man die Patches anklicken kann und dabei eine Callback-Funktion aufgerufen wird, die die Information um welchen Patch es sich handelt (d.h. die Werte von trial und val) übergeben bekommt. Nachfolgend der bisherige Code und ein Beispiel das Plots:
Code:
hPlot2 = subplot(1,1,1);%subplot(1,2,2);
hold on;
hCols = bar3(diffmat);
nTrials = size(diffmat,1);
xpatch = [00.100.100];
ypatch = [000.100.10];
offset_x = 0.03;
offset_y = 0.05;
for trial=0:nTrials-1 for val=0:length(hCols)-1 % Estimate the color.
ind_tr = nTrials-trial; % trial index in the matrix: top-down
value = diffmat(ind_tr,val+1);
if(value>6 || value<-6) color = [0.400];
elseif(value>4 || value<-4) color = [0.90.90];
elseif(value>2 || value<-2) color = [00.91];
else color = [001];
end % Draw the patch. patch(val*0.1+xpatch, trial*0.1+ypatch, color);
text(val*0.1+offset_x, trial*0.1+offset_y, num2str(round(value)));
end end
xlim(hPlot2, [0length(hCols)*0.1]);
ylim(hPlot2, [0 nTrials*0.10]);
set(hPlot2, 'xtick', 0:0.1:(length(hCols)-1)/10,'xticklabel', colnames);
% Set X tick labels.
nLabels = length(valnames);
for j=1:nLabels
tmp{j}=valnames{nLabels-j+1};
end
valnames = tmp;
set(hPlot2, 'ytick', 0.05:0.1:(size(diffmat,1))/10, 'yticklabel', valnames);
lt = get(hPlot2, 'XTickLabel');
xt = get(hPlot2, 'XTick');
set(hPlot2,'XTickLabel',[]);
text(xt+0.05,repmat(-0.02,length(xt),1),lt,'HorizontalAlignment','right','rotation',90);
% Set the aspect ratio and the y limit to exclude distortion. set(hPlot2, 'DataAspectRatio', [111]);
ylim([0size(diffmat,1)/10]);
title('2D');
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.