且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用2D数组设置Matlab线图图的XData?

更新时间:2022-11-10 08:29:01

要设置多个属性(由于p是线对象的句柄数组),属性名称以及要设置的属性必须是单元格数组,请参见例如此文档页面将线型设置为多行的不同值"下例如.

To set multiple properties (as p is an array of handles to line objects), the property name as well as the properties to set need to be cell arrays, see e.g. this documentation page under "Set Line Style to Different Value for Multiple Lines" for an example.

在您的示例情况下,这将起作用:

In your example case, this would work:

set(p, {'XData'}, mat2cell(new_data, ones(1,3), 3));

另请参见 mat2cell ,在这种情况下,我会使用它将new_data整形为3x1的单元格数组,每个数组包含来自new_data的1x3行.

See also mat2cell, in this case I use it to reshape new_data to a 3x1 cell array each containing a 1x3 row from new_data.