【发布时间】:2019-08-24 02:49:08
【问题描述】:
我试图在 matlab 中做一个 GUI,它接受表中的值以将其转换为矩阵,但想法是用户可以先设置行数和列数。
面板看起来像这样
按钮的代码是
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)
rows =str2double(get(handles.edit_rows,'String'));
cols=str2double(get(handles.edit_cols,'String'));
num_elem=cell(rows,cols);
num_elem(:,:)={"};
set(handles.uitable1,'Data',num_elem)
set(handles.uitable1,'ColumnEditable',true(1,cols))
但是,如何导出或转换为矩阵,以便我可以对其应用函数?
更新 在 byetisener 的帮助下,我将代码更新为 function pushbutton1_Callback(hObject, eventdata, 句柄)
% 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)
filas=str2double(get(handles.edit_fila,'String'));
column=str2double(get(handles.edit_col,'String'));
num_elem=cell(filas,column);
num_elem(:,:)={''};
set(handles.uitable1,'Data',num_elem)
set(handles.uitable1,'ColumnEditable',true(1,column))
handles.uitable1.Data = cell(filas, column);
matrix = cell2mat(handles.uitable1.Data);
matrix
它没有获取单元格的值,假设按钮调整大小并同时复制值,如果不是,一旦矩阵调整大小,如何在另一个按钮中复制?
【问题讨论】:
-
您想将单元格值转换为正确的数字吗?
-
是的,没错!
-
单元格可以包含多种数据类型。只需访问单元格,并将其转换为您想要的类型。根据您的代码,您的单元格内容已经是双倍的。
标签: matlab user-interface linear-algebra