Reputation: 173
I have a Matlab .fig file. (Basically a pcolor plot). I want to extract the matrix (like rows and columns into an array variable) from this image. How do I do this? Thanks for any inputs or pointers.
Upvotes: 1
Views: 1063
Reputation: 128
In addition to Luis Mendo's answer, I want to point out that MATLAB supports dot-notation and if performance is any concern, dot-notation should always be preferred over the set()/get() methods.
Using the handle()
function wrapper along with dot-notation is fastest for both setting and getting of handle class properties.
>> 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
For timing experiments and details see: Undocumented MATLAB
Upvotes: 0
Reputation: 112659
The axes have a child, which is an object of type surface
if you used the pcolor
function, or of type image
if you used the image
function. The matrix is in the CData
property of this object:
>> 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
Upvotes: 2