Return plot handles at figure close

4 Ansichten (letzte 30 Tage)
Chris Nemecek
Chris Nemecek am 26 Jul. 2018
Beantwortet: Chris Nemecek am 31 Jul. 2018
I have App with a Plot button that executes a plotting routine when it is pushed. The PlotPushDown callback creates a figure with several subplots. For each plot command i return the plot handle and store it. Upon closing the figure, I would like to return the latest plot handles. I am using BrushData, so the plot handles can change with user interaction. Upon closing the figure I need to access the latest BrushData for more data processing.
function PlotButtonPushed(app, event)
%%Plot all source data for a given weather property %%
% Create figure
f = figure('CloseRequestFcn',@getBrushData); hold on; brush on;
% If User Input is selected, adjust length by -1
if any(strcmp(app.ListBox.Value,'User Input'))
n = length(app.ListBox.Value) - 1;
else
n = length(app.ListBox.Value);
end
% Plot
switch app.DropDown.Value
case 'Pressure'
for i = 1:length(app.ListBox.Value)
switch app.ListBox.Value{i}
case 'TRAP'
subplot(n,1,i)
h{i} = plot(app.allData.trapTime,app.allData.trapPressure,'LineWidth',2);
h{i}.Tag = 'Time';
title('TRAP')
xlabel('Time (s)')
ylabel('Pressure (psia)')
xlim([-10 10])
grid on;
tmp{i} = zeros(1,length(app.allData.trapTime));
tmp{i}(app.t0Data.trapIDX) = 1;
h{i}.BrushData = tmp{i};
case 'Balloon'
subplot(n,1,i)
h{i} = plot(app.allData.balloonAltitude,app.allData.balloonPressure,'LineWidth',2);
h{i}.Tag = 'Altitude';
title('Balloon Data')
xlabel('Altitude (ft)')
ylabel('Pressure (psia)')
xlim([0 600])
grid on;
case 'Measured'
subplot(n,1,i)
h{i} = plot(app.allData.measurementTime,app.allData.measurementPressure,'LineWidth',2);
h{i}.Tag = 'Time';
title('Measurement Data')
xlabel('Time (s)')
ylabel('Pressure (psia)')
xlim([-10 10])
grid on;
tmp{i} = zeros(1,length(app.allData.measurementTime));
tmp{i}(app.t0Data.measurementIDX) = 1;
h{i}.BrushData = tmp{i};
case 'User Input'
for j = 1:length(app.ListBox.Value) - 1
subplot(n,1,j); hold on;
if strcmp(h{j}.Tag,'Time')
plot(0,app.pInput.Value,'o','MarkerSize',10,'MarkerEdgeColor','r','MarkerFaceColor','g')
elseif strcmp(h{j}.Tag,'Altitude')
plot(app.t0Data.Altitude,app.pInput.Value,'o','MarkerSize',10,'MarkerEdgeColor','r','MarkerFaceColor','g')
end
end
end
end
case 'Temperature'
case 'Wind Speed'
case 'Wind Direction'
case 'Relative Humidity'
case 'Dew Point'
end
waitfor(f);
end
function getBrushData(src,evt)
% setappdata(0,'h',h)
disp('aaa')
closereq
end
After the waitfor(f) command, I need access to the last plot handles (h) for more data processing.
Is there a way to achieve this? I have tried via the CloseRequestFcn, but I can't seem to get it to work. Is there something I need to do, or is there a better way?

Akzeptierte Antwort

Chris Nemecek
Chris Nemecek am 31 Jul. 2018
Here is the way I solved this issue.
In the App:
function PlotButtonPushed(app,event)
f = figure('CloseRequestFcn',@getBrushData); hold on; brush on;
% plot stuff here
waitfor(f);
end
CloseRequestFcn:
function getBrushData(src,evt)
f=findobj(gcf,'Type','line');
for i = 1:length(f)
brushedData{i} = f(i).BrushData; % Get brush data info
identifier{i} = f(i).Parent.Title.String; % Get subplot title
brushIndices{i} = find(brushedData{i}); % Get indices that are brushed
setappdata(0,'identifier',identifier)
setappdata(0,'brushedData',brushedData)
setappdata(0,'brushIndices',brushIndices)
closereq
end
end

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by