如何在 Matlab 中从 .fig 中提取矩阵?
How to extract a matrix from a .fig in Matlab?
我有一个 Matlab .fig 文件。 (基本上是 pcolor 图)。我想从此图像中提取矩阵(如行和列到数组变量中)。我该怎么做呢?感谢您的任何输入或指示。
轴有一个子对象,如果您使用 image
函数,它是 surface
if you used the pcolor
function, or of type image
类型的对象。矩阵在这个对象的CData
属性中:
>> x = magic(3) % example data
x =
8 1 6
3 5 7
4 9 2
>> pcolor(x) % generate image
>> get(get(gca,'Children'),'CData') % retrieve the data
ans =
8 1 6
3 5 7
4 9 2
除了 Luis Mendo 的回答之外,我想指出 MATLAB 支持点表示法,如果性能有任何问题,点表示法应始终优先于 set()/get() 方法。
使用 handle()
函数包装器和点符号是设置和获取句柄 class 属性最快的方法。
>> x=magic(3)
x =
8 1 6
3 5 7
4 9 2
>> pcolor(x)
>> ax = handle(gca);
>> ax.Children.CData
ans =
8 1 6
3 5 7
4 9 2
有关计时实验和详细信息,请参阅:Undocumented MATLAB
我有一个 Matlab .fig 文件。 (基本上是 pcolor 图)。我想从此图像中提取矩阵(如行和列到数组变量中)。我该怎么做呢?感谢您的任何输入或指示。
轴有一个子对象,如果您使用 image
函数,它是 surface
if you used the pcolor
function, or of type image
类型的对象。矩阵在这个对象的CData
属性中:
>> x = magic(3) % example data
x =
8 1 6
3 5 7
4 9 2
>> pcolor(x) % generate image
>> get(get(gca,'Children'),'CData') % retrieve the data
ans =
8 1 6
3 5 7
4 9 2
除了 Luis Mendo 的回答之外,我想指出 MATLAB 支持点表示法,如果性能有任何问题,点表示法应始终优先于 set()/get() 方法。
使用 handle()
函数包装器和点符号是设置和获取句柄 class 属性最快的方法。
>> x=magic(3)
x =
8 1 6
3 5 7
4 9 2
>> pcolor(x)
>> ax = handle(gca);
>> ax.Children.CData
ans =
8 1 6
3 5 7
4 9 2
有关计时实验和详细信息,请参阅:Undocumented MATLAB