【问题标题】:How do I save histogram to file in matlab?如何将直方图保存到matlab中的文件?
【发布时间】:2014-05-14 15:30:33
【问题描述】:
figure;
histogram = hist(np,180);
name=['histogram-' int2str(k) '.png'];  
%% k is the iterator so basically I want to save all the images using a loop.
imwrite(out,name);

我得到的图像只是一条水平线。有人知道如何解决这个问题吗?

【问题讨论】:

    标签: matlab save histogram


    【解决方案1】:

    你可以用 savefig 代替 imwrite

    这里是文档 http://www.mathworks.ch/ch/help/matlab/ref/savefig.html

    savefig(h,filename)
    

    h 是图形的句柄。你可以跳过 h 来保存当前的图。

    (edit) savefig 可能不存在,具体取决于 MATLAB 版本。 2012b不退出。

    所以saveas 可能会更好:

    f=figure;
    hist([1 2 2 3]);
    saveas(f, 'histogram-1.png')
    

    这在 MATALB 2012b 中有效。您也可以将其另存为 .fig。

    【讨论】:

    • 我尝试了你的方法,但它给了我一个错误“未定义函数 'savefig' 用于输入参数类型'double'”
    • 我明白了。可能你应该从图而不是从历史中获得句柄。所以,图=图;和 savefig(fig, "histogram-1.pgn")。我现在没有 matlab,所以我猜。
    • 我试了又失败了。对于 saveas 命令,我收到错误“无效的 Simulink 对象句柄”
    • 嗯。也许尝试以这种方式处理stackoverflow.com/a/4540682/566035
    猜你喜欢
    • 2013-09-30
    • 2018-08-24
    • 2019-12-23
    • 2012-06-27
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    相关资源
    最近更新 更多