MATLAB Answers

How do i write a code which gets the values of the table data with pop up menus and makes the user do something when a particular case was chosen?

1 view (last 30 days)
sachin narain
sachin narain on 20 Apr 2018
Edited: sachin narain on 21 Apr 2018
My created UItable has datas which have popup menus like this.(Table image attached along with the question).Now i want to write a code which gets the datas of the table and checks which case was chosen.For this should i choose createafunction for the uitable and write my cases?In which function block should i write the code when a particular case was chosen?

  2 Comments

Mahesh
Mahesh on 20 Apr 2018
Could you bit more clear.you select the "environment" and "location" and tick the "Authorised". Then it should do some work right?
sachin narain
sachin narain on 20 Apr 2018
Yes.you understood it right.Say for example i check the authorised box if the user chooses a particular environment and a particular location

Sign in to comment.

Accepted Answer

Mahesh
Mahesh on 20 Apr 2018

I presume your uitable choice data the enviroment and location have the strings

 v = get(handles.checkbox1, 'Value');
  tdata = get(handles.uitable, 'data');
  a=strcmp(tdata((contains(tdata(:,1),'your_Environment'))),'your_Environment');
  b=strcmp(tdata((contains(tdata(:,1),'your_City'))),'your_City');
  if (v && a && b)==1
  %% do something
  else
   %% do something
  end

  1 Comment

sachin narain
sachin narain on 21 Apr 2018

Ok.Got it.But my checkbox is already inside the Uitable and i created by making that particular cell(in the uItable) as format 'logical'.and that doesnt have a particular handles tag.(like the one you have given handles.checkbox1).I will attach my code of how i created this particular table.That will make things clearer about my asked question

 function TerrainGUI_v2_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 TerrainGUI_v2 (see VARARGIN)
type_environment ={'Segm', 'Arc' ,'Circuit', 'Intersection' ,'Round', 'Spline'};
type_Location ={'City', 'Country' ,'Highway'};
slope = [{''}];  
len_Portions = [{''} {''} slope]; 
radius_Portions = [{''}];
authorised ={false} ;              
tabledata =[type_environment(1) type_Location(1) len_Portions slope radius_Portions authorised]; % A condition has to be added that if i add a straight line i should disable the radius of portions
%Column_to_affect = 5;
% tabledata (:,Column_to_affect) = cellfun(@num2str, tabledata(:,Column_to_affect), 'uniform', 0);
columnname ={'Environment','Location','Length of Portions','Slope','Radius of portions','Authorised'};
columnformat = {type_environment,type_Location,'numeric','numeric','numeric','logical'};
columneditable = [true true true true true true] ;
set(handles.table_Tracks,'ColumnName',columnname,'ColumnWidth','auto','Data',tabledata,'ColumnFormat', columnformat,'ColumnEditable', columneditable,'RowName',[],'BackgroundColor',[.7 .9 .8],'ForegroundColor',[0 0 0] );
% Choose default command line output for TerrainGUI_v2
handles.output = hObject;

% Update handles structure guidata(hObject, handles); end

Sign in to comment.

More Answers (0)

Sign in to answer this question.