Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 在MATLAB中添加图像时无法保持轴固定_Image_Matlab_Matlab Figure - Fatal编程技术网

Image 在MATLAB中添加图像时无法保持轴固定

Image 在MATLAB中添加图像时无法保持轴固定,image,matlab,matlab-figure,Image,Matlab,Matlab Figure,我目前正致力于在MATLAB中创建一个基于GUI的21点游戏。我为庄家牌和玩家牌设置了两个轴,如下所示: self.window = figure('Name', 'Blackjack',... 'Units', 'normalized',... 'Position', [.02, .05, .95, .85]); self.dealerHand = axes('Parent', self.window,... 'XLimMode', 'manual',... '

我目前正致力于在MATLAB中创建一个基于GUI的21点游戏。我为庄家牌和玩家牌设置了两个轴,如下所示:

self.window = figure('Name', 'Blackjack',...
    'Units', 'normalized',...
    'Position', [.02, .05, .95, .85]);
self.dealerHand = axes('Parent', self.window,...
    'XLimMode', 'manual',...
    'XLim', [0, 10],...
    'YLimMode', 'manual',...
    'YLim', [0, 1],...
    'Title', 'Dealer',...
    'Units', 'normalized',...
    'Position', [.05, .70, .90, .25]);
self.playerHand = axes('Parent', self.window,...
    'XLimMode', 'manual',...
    'XLim', [0, 10],...
    'YLimMode', 'manual',...
    'YLim', [0, 1],...
    'Title', 'Player',...
    'Units', 'normalized',...
    'Position', [.05, .20, .90, .25]);
如您所见,我已将“手动”XLim和YLim模式都设置为手动。但是,当我运行此脚本时:

bjWindow = BlackJackWindow;
deck = DeckOfCards;
deck.shuffle
playerHand{1} = deck.cards{1};
dealerHand{1} = deck.cards{2};
playerHand{2} = deck.cards{3};
dealerHand{2} = deck.cards{4};
hold on
image(bjWindow.dealerHand, [0, 1], [0, 1], dealerHand{1}.img)
image(bjWindow.dealerHand, [1, 2], [0, 1], dealerHand{2}.img)
hold off
hold on
image(bjWindow.playerHand, [0, 1], [1, 0], playerHand{1}.img)
image(bjWindow.playerHand, [1, 2], [1, 0], playerHand{2}.img)
hold off
经销商“手动”自动调整和拉伸第二张卡,如下所示:

如果我在第一个代码块中反转手的顺序,则错误发生在播放器“手”中。换句话说,在初始化窗口时首先创建的轴都有此错误。另一个问题不那么重要,因为我找到了一个解决方法,那就是为什么玩家“手”翻转轴,以至于我必须将y位置设置为[1,0],而不是[0,1]?

会影响当前轴,这是您最后一个轴。将图像添加到所创建的第一个轴时,图像将被重置。反转是其中的一部分,因为在显示图像时,
image
会反转y轴

解决办法是使用

hold(bjWindow.dealerHand,'on')
hold(bjWindow.playerHand,'on')
我建议不要在策划后再次关闭暂停。没有必要

相反,要更改显示的卡片,请替换。这是存储像素数据的地方。通过更新此属性,而不是创建新的图像对象,您的应用程序将更加平滑,并且您无需担心删除和重新创建图像对象、保留轴属性等。更新此属性非常简单,因为您的所有gliph(我想)都具有相同的大小

set(image_handle,'CData',playerHand{1}.img)