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

조회 수: 1 (최근 30일)
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?
%

채택된 답변

Sean de Wolski
Sean de Wolski 2014년 4월 29일
  • 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
Sean de Wolski
Sean de Wolski 2014년 4월 29일
It's really hard to say without being able to run the files. Can you attach them?
Lewis
Lewis 2014년 4월 29일
편집: Lewis 2014년 4월 29일
Okay no problem, all attached as a zip. Thanks for the help! edit: okay file has been fixed.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by