Clear Filters
Clear Filters

Matlan操作咨询

5 views (last 30 days)
bowen
bowen on 25 Mar 2024
Answered: Brahmadev on 3 Apr 2024
1. 如何在App Designer 里引用外部类,进行面向对象编程?
2. 在表格中,能否将字符串、单选框等不同格式的数据放在同一列中?
3. Matlab是否存在与Microsoft office接口的工具箱?比如Matlab输出的excel文件,这个输出的excel文件可以自动依据Matlab代码进行相关的格式上的编辑?

Answers (1)

Brahmadev
Brahmadev on 3 Apr 2024
Hi @bowen,
我将用英语回答您的疑问,以便更快地回复。
For your first question, you can create an object for any class that is there on the MATLAB path. For example, if the class definition is:
% ExampleClass.m
classdef ExampleClass
properties
Data
end
methods
function obj = ExampleClass(data)
obj.Data = data;
end
function data = getData(obj)
data = obj.Data;
end
end
end
It can be called inside a button callback function as:
% Callback function for a button
function ButtonPushed(app, event)
myObject = ExampleClass('Hello World');
disp(myObject.getData());
end
For your second question, since the entire column of the table are designed to hold a single data type, it is not possible to use UITable for this. But you can create a custom layout using UIGridLayout and add buttons and string as needed. Refer to the following documentation for more information:
For your third question, we can easily read Excel files and manipulate the data in MATLAB and export it back to Excel. Refer to the documentations of the following functions for more information and usage:
  1. "readtable" for importing an Excel file or other tabular data to MATLAB: https://www.mathworks.com/help/matlab/ref/readtable.html
  2. "writetable" writes to a file with the name and extension specified by filename. https://www.mathworks.com/help/matlab/ref/writetable.html
Hope this helps!

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!