Turn a MATLAB plot into image

后端 未结 2 1519
生来不讨喜
生来不讨喜 2020-12-02 00:31

I have generated a plot like

figure; hold;
axis([0 10 0 10]);
fill([ 1 1 5 5], [5 1 1 5],\'b\')

and now I want to have this plot as an matr

相关标签:
2条回答
  • 2020-12-02 01:06

    What are the desired characteristics of your target matrix ? And what sort of images do you want to rasterise ?

    You see, for the only example you have given us it's almost trivial to define a matrix representing your image ...

    1. figmat = ones(10,10,3) % create a 10x10 raster where each entry is a triple for RGB, setting them all to 1 colours the whole raster white
    2. figmat(2:5,2:5,1:2) = 0 % sets RG components in the coloured area to 0, leaving only blue
    

    Your matrix is a raster to start with. Now, you can use the built-in function image to visualise your matrix. Have a look at the documentation for that function. And note that my suggestion does not meet the spec for use with image() and colormap().

    0 讨论(0)
  • 2020-12-02 01:21

    You can use GETFRAME function. It returns movie frame structure, which is actually rasterized figure. Field cdata will contain your matrix.

    F=getframe;
    figure(2)
    imagesc(F.cdata);
    
    0 讨论(0)
提交回复
热议问题