Update control chart or plot automatically using concentrated data from uitable based on column selection.

13 vues (au cours des 30 derniers jours)
Hello All,
I have a question about automatically updating a control chart or plot using data the user inputs into a uitable (I want a control chart, but if it is easier to use plot() instead of controlchart() I will). The control chart or plot would have to change depending on where the user clicks on the uitable, or, in other words, what column the user has selected (by clicking into a cell in that column or using the arrow keys to navigate to that column). I have actually successfully managed to set this system up, however it is insanely slow and not very intuitive. I determine what rows and columns the user has selected using this type of setup,
uiIndex=findjobj(hObject);
rows=uiIndex.getComponent(0).getComponent(0).getSelectedRows+1;
cols=uiIndex.getComponent(0).getComponent(0).getSelectedColumns+1;
after which I refresh the control chart based on the column using the following code:
function ControlChartRefresh(handles,hObject,rows,cols)
%get control chart data from appdata, such as the control limits
AppStruct=getappdata(0,'AppStruct');
% CLSection is control limit section. this contains the column names in which the user inputs numerical data % % and their corresponding control limits
CLSection=AppStruct(1).ControlChart;
% get column names from uitable
ColNames=get(handles.uitable1,'ColumnName');
% get data from uitable
UiTableData=get(handles.uitable1,'Data');
% get user selected column from uitable
UiTableDataCol=UiTableData(:,cols);
% determine the length of that column
ColLength=length(UiTableDataCol);
% find all blank cells
[nrows,~]=find(~cellfun('isempty',UiTableDataCol));
if isempty(nrows)==1 % if there all cells are blank then show a message of "No Data Found" on plot window
axes(handles.DataControlChart);
cla reset;
text(0.35,0.5,'No Data Found','Units','Normalized','Parent',handles.DataControlChart,'FontSize',15);
title('');
ylabel('');
set(handles.DataControlChart,'xtick',[],'ytick',[],'Color',[0.8 0.8 0.8])
return;
disp('NoData')
else
%convert all strings to doubles in user selected column
UiTableDataColdoubled=cellfun(@str2double,UiTableDataCol);
% find all cells that are NaN's
UiTableDataColNotNaN= ~isnan(UiTableDataColdoubled);
% recreate column with non-NaN elements
UiTableDataColFinal=UiTableDataColdoubled(UiTableDataColNotNaN);
end
% Get schema Data and using the selected box's index, find the Lower control limit,center line,upper control limit,
% and determine whether the dimension is pass or fail based upon the Appdata CLSection
% compare the CLSection from the appdata structure to the column name. (CLSection is control limit section)
[CLimRow,~]=find(strcmpi(CLSection(:,1),ColNames{cols,1}));
% convert String control limits to numeric
ControlLimits=str2num(CLSection{CLimRow,2});
% get the standard deviation
sigma=std(UiTableDataColFinal);
% if the std is 0, NaN, or is empty then std=1e-10
if sigma==0 || isnan(sigma)==1 || isempty(UiTableDataCol)==1
sigma = 1e-10;
width = length(nrows);
else
width=length(UiTableDataColFinal);
end
ax=handles.DataControlChart;
cla reset;
controlchart(UiTableDataColdoubled,'chart','i','width',width,...
'sigma',sigma,'limits',ControlLimits,'Parent',handles.DataControlChart);
ax.XTick= 1:1:ColLength;
ax.XLim =[1,ColLength];
ax.Title.String='';
ax.XLabel.String = '';
ax.YLabel.String = '';
I am currently reading up on linkdata and refresh data, but I do not how to set it up given my situation. Meaning I do not know if it can be used for a control chart setup.
any suggestions or help would be appreciated. I tried to be detailed, but if you need a more concise description please let me know.
I have attached a pic of my program GUI for potential clarification.
EDIT: for clarification a "Schema" is a template the user selects before this program runs which sets the parameters. This includes, but is not limited to, the column names,how many columns there are, and control limits for each column selected.

Réponse acceptée

Stephen Morris
Stephen Morris le 18 Avr 2016
Modifié(e) : Stephen Morris le 18 Avr 2016
So, I answered my own question. I created a test program and used link data and refresh data to successfully update a control chart based on the users column selection. Using GUIDE i created a quick gui with a single uitbale and plot axes. the code below is the opening function and a custom refresh function I created which is called every time the user selects or edits a cell. Below is the test program I used:
% --- Executes just before LinkDataTest is made visible.
function LinkDataTest_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to LinkDataTest (see VARARGIN)
% Choose default command line output for LinkDataTest
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
X=[1:4]
UiTableData=get(handles.uitable1,'Data')
UiTableDataCol=UiTableData(:,1)
UiTableDataColDBL=cellfun(@str2double,UiTableDataCol)';
assignin('base','UiTableDataColDBL',UiTableDataColDBL)
Y=UiTableDataColDBL
%p=plot(X,Y,'*','Parent',handles.axes1)
width=X(end)
sigma=std(UiTableDataColDBL)
if isnan(sigma)==1 || strcmpi('NaN',sigma)==1
sigma=1
end
ControlLimits=[7.55 7.60 7.65]
p=controlchart(Y,'chart','i','width',width,'sigma',sigma,'limits',ControlLimits,'Parent',handles.axes1)
% line([0 4],[4 4],'Color','b')
% line([0 4],[3 3],'Color','r')
% line([0 4],[1 1],'Color','b')
p.XDataSource='X';
p.YDataSource='Y';
p.sigma='sigma';
p.width='width';
p.limits='ControlLimits'
linkdata on
function refreshchart(handles)
uiIndex=findjobj(handles.uitable1);
cols=uiIndex.getComponent(0).getComponent(0).getSelectedColumns+1;
UiTableData=get(handles.uitable1,'Data')
UiTableDataCol=UiTableData(:,cols)
UiTableDataColDBL=cellfun(@str2double,UiTableDataCol)';
assignin('base','UiTableDataColDBL',UiTableDataColDBL)
X=[1:4]
Y=UiTableDataColDBL
width=X(end)
sigma=std(UiTableDataColDBL)
if isnan(sigma)==1 || strcmpi('NaN',sigma)==1
sigma=1
end
refreshdata(handles.axes1,'caller')

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by