【问题标题】:Plot in MATLAB based on User Input根据用户输入在 MATLAB 中绘图
【发布时间】:2016-04-13 02:52:49
【问题描述】:

我目前正在使用以下函数在 MATLAB 中绘制单个图形

PlotImage(finalImage, 1, 4, 4, 'Final Image');

function[] = PlotImage(image, y, x, value, name)
subplot(y,x,value);
imagesc(image);
axis image;
title(name);
end

我有几个“finalImages”,我想根据用户输入显示,即程序默认显示图像 1,然后如果在键盘上按下键 1 - 5,它将使用不同的图像再次调用 PlotImage(图像1 - 5)。

有没有办法做到这一点? KeyPressFcn 上的文档似乎对我没有帮助。

【问题讨论】:

    标签: matlab matlab-figure


    【解决方案1】:

    您需要指定一个KeyPressFcn 来处理按键事件并调用所有必要的绘图命令(并且可能涉及调用PlotImage

    hfig = figure('WindowKeyPressFcn', @(src,evnt)keypress(evnt));
    
    %// Create 5 "images" to show
    finalImages = {rand(4), rand(4), rand(4), rand(4), rand(4)};
    
    function keypress(evnt)
        if ismember(evnt.Key, '12345')
            img = finalImages{str2double(evnt.Key)};
            PlotImage(img, 1, 4, 4, 'Final Image');
        end
    end
    
    function PlotImage(img, y, x, value, name)
        subplot(y,x,value);
        imagesc(img);
        axis image;
        title(name);
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-30
      • 2019-05-05
      • 2014-11-15
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多