How to add rows in a gui uitable when adding a new line to a plot from a pop-up menu

I just lost all the question i just asked so I will try and write this really quickly:
First problem is that when i select a new species from my pop-up menu which plots a new line on my axes, the uitable replaces my previous plots data not adding a new row of data. How would i make my loop add a new row for each plot i add to the axes?
Second problem is that the auto-size feature for the uitable means that all of the data is not seeable without a scroll bar, is there a way to make the uitable sort of "fit-to-page".
here is my code:
function Start_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 Start (see VARARGIN)
% Choose default command line output for Start
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
%
[num, txt, raw] = xlsread('Speciesdata.xlsx',1,'a2:f18');
set(handles.bigbox,'UserData',num);
set(handles.popupmenu1, 'String', txt);
set(get(handles.plot_area,'XLabel'),'String','Temperature ()')
set(get(handles.plot_area,'YLabel'),'String','Saturation Pressure ()')
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
contents = get(handles.popupmenu1,'Value');
num = get(handles.bigbox,'UserData');
if contents < 17
n = contents;
set(handles.uitable1, 'Data', num(n,1:5));
else n = 17;
end
t = num(n,4):4:num(n,5);
y = 10.^(num(n,1) - (num(n,2)./(num(n,3) + t)));
line(t,y);
Any help would be appreciated!
Extra questions: Is there a way to limit the amount of line plots allowed on an axes? Is there a way to make the colour of the line alternate?
Is there a way to have "static text" in the table? As a way to label the columns and rows?
%

 Accepted Answer

  • 1) Before you set the Data of the uitable, get the previous data and concatenate it with the new
existingData = get(handles.uitable,'Data')
newData = [existingData; num(n,1:5)]
set(handles.uitable,'Data',newData)
  • 2) Set the 'Columnwidth' property of the uitable to auto
set(handles.uitable,'ColumnWidth','auto')
  • Bonus 1) Just check how many line children of the axes exist and if it's greater than the threshold delete one or don't plot a new line:
ax = axes;
plot(magic(5)) % five lines
lineHandles = findobj(ax,'type','line')
  • Bonus 2) Sure!
doc text
doc annotation

5 Comments

Wow very fast and useful reply, thank you very much!
At the moment though, the data on the table is now just two rows of the same information... any ideas?
Well you'll need to figure out what the new information is and include that in data. I don't know what that is...
I understand that, my main issue, and forgive me If i am being stupid here, is that my if function determines which row of my imported data to retrieve (what n is used for) and as far as I can tell the issue is that iteration runs through the value of existingData as well as newData but moving existinngData outside of the loop creates an error due to the loop itself defining what the first data within the uitable is. Also any mention of n will also cause an error as the if function assigns the value to n in the first place.
Would this mean I have to create another statement which checks if any data as been selected then if so creates the newData?
I apologise again, this whole thing is a bit out of my depth but has to be done :/!
It's really hard to say without being able to run the files. Can you attach them?
Okay no problem, all attached as a zip. Thanks for the help! edit: okay file has been fixed.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

on 29 Apr 2014

Edited:

on 29 Apr 2014

Community Treasure Hunt

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

Start Hunting!