国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

matlab 動態增加uitable內容

2019-11-08 18:21:52
字體:
來源:轉載
供稿:網友

matlab 動態增加uitable內容

在利用matlab設計GUI程序時,uitable控件通常用來展示數據。而這些需要展示在GUI面板中的數據不是一層不變的,有的時候會動態地增加和變動。當數據需要動態增加時,需要考慮橫向和縱向數據增加的情況。因此總結以下uitable數據橫向和縱向動態增加的情況。

1、橫向增加

設計一個GUI程序如下圖所示:

主要的功能是橫向地增加數據并在uitable內顯示數據。主要效果如下所示:

                                        -----------------

代碼如下:

% --- Executes on button PRess in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)%增加一列的按鈕函數。對應的按鈕為圖中的【增加】按鈕的功能
content1 = str2double(get(handles.edit1,'String'));content2 = str2double(get(handles.edit2,'String'));content3 = str2double(get(handles.edit3,'String'));content4 = str2double(get(handles.edit4,'String'));uitabledata = get(handles.uitable1,'data');handles.uitabledata = uitabledata;%將uitable內原來的數據保留下來,方便下次撤下動作時的數據恢復guidata(hObject,handles);%將content1-4和原來的數據組織成為uitable控件數據olddata = uitabledata;newcol = [content1 content2 content3 content4]';if isempty(olddata)    newdata = newcol;else    newdata = [olddata newcol];endset(handles.uitable1,'data',newdata);%將新增加的數據和原來的數據組成newdata,然后寫入uitable1中。
% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton2 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)%將剛才添加的那一列撤銷,對應于圖中的【重置】按鈕的功能olddata = handles.uitabledata;set(handles.uitable1,'data',olddata);% --- Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton3 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)%將整個uitable清空,對應于圖中的【清空】按鈕的功能set(handles.uitable1,'data',[]);% --- Executes during object creation, after setting all properties.function uitable1_CreateFcn(hObject, eventdata, handles)% hObject    handle to uitable1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns calledset(hObject,'data',[]);%進入該GUI界面時,初始化uitable內容為空。

2、縱向增加

縱向增加數據并動態地在uitable控件中顯示,即增加uitable內數據的行數,基本原理類似。

首先設計如下GUI界面:

其效果如下所示:

                                  .................................

具體程序如下:

% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)%縱向動態增加數據,對應圖中的【增加】按鈕功能%首先將edit控件內的數據取出來content1 = str2double(get(handles.edit1,'string'));content2 = str2double(get(handles.edit2,'string'));content3 = str2double(get(handles.edit3,'string'));%取出原來uitable內容,并保存到handles內便于數據的重置操作uitabledata = get(handles.uitable1,'data');handles.uitabledata = uitabledata;guidata(hObject,handles);%將原來uitable的內容和新的內容組織成新數據olddata = uitabledata;newrow = [content1 content2 content3];newdata = [olddata;newrow]; %將新數據寫入uitable內set(handles.uitable1,'data',newdata);% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton2 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)%撤銷剛才增加的那行數據,對應圖中的【重置】按鈕功能set(handles.uitable1,'data',handles.uitabledata);% --- Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton3 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)%清空該uitable控件內容,對應圖中的【清空】按鈕功能set(handles.uitable1,'data',[]);% --- Executes during object creation, after setting all properties.function uitable1_CreateFcn(hObject, eventdata, handles)% hObject    handle to uitable1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns calledset(hObject,'data',[]);%進入GUI頁面程序并顯示該uitable控件時,初始化其內的數據為空。


上一篇:第13章 使用sed處理文本

下一篇:PAT 1046

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阳谷县| 临桂县| 邹平县| 天水市| 汝南县| 凯里市| 绥滨县| 尼勒克县| 青龙| 太湖县| 醴陵市| 嘉定区| 根河市| 津南区| 延川县| 梁山县| 金门县| 威海市| 大渡口区| 灌南县| 洪江市| 辽宁省| 五常市| 恩施市| 兰坪| 城步| 固阳县| 新晃| 哈密市| 兴宁市| 抚州市| 宝应县| 台南县| 天峨县| 开封县| 财经| 福安市| 资溪县| 芦溪县| 曲水县| 阳春市|