Selecting a random digit from a vector except for one digit that should not show except when at least 5 of the other digits were shown

1 回表示 (過去 30 日間)
Using AppDesginer, I want to show one digit at a time on the screen (a I created a vector from 0 to 9) and let's say I want the last number to only show when at least other 5 digits from the vector were shown before it. Can you please help me?

採用された回答

Walter Roberson
Walter Roberson 2019 年 7 月 19 日
min_before = 5;
lb = 0; ub = 9;
candidates = lb:ub;
special = randi([lb ub]);
not_special = setdiff(candidates, special);
order1 = randperm(length(not_special), min_before);
first_group = not_special(order1);
remainder = [special, setdiff(not_special, first_group)];
order2 = randperm(length(remainder));
second_group = remainder(order2);
order = [order1 order2];
  4 件のコメント
Dana Cherri
Dana Cherri 2019 年 7 月 20 日
It is showing "Invalid default value for property 'candidates' in class 'app1':
Undefined function or variable 'lb' " although I referred to the class name.
This is the code:
classdef app1 < matlab.apps.AppBase
properties (Access = private)
Property % Description
min_before = 5;
lb = 0;
ub = 9;
candidates = lb:ub;
special = 3;
not_special = setdiff(candidates, special);
order1 = randperm(length(not_special), min_before);
first_group = not_special(order1);
remainder = [special, setdiff(not_special, first_group)];
order2 = randperm(length(remainder));
second_group = remainder(order2);
order = [order1 order2];
font = [48 72 94 100 120];
height = 12:29;
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: ReadyButton
function ReadyButtonPushed(app, event)
app.ReadyButton.Visible = 'off';
app.HelloLabel.Text = 'Hello';
app.HelloLabel.FontColor = [1 1 1];
pause(1);
for ii = 1:160
tstart = tic;
app.HelloLabel.Text = app.order(ii);
pause(0.25);
app.HelloLabel.Text = 'X';
pause(0.9);
app.HelloLabel.Text = app.order(ii);
telapsed = toc(tstart);
end
end
Walter Roberson
Walter Roberson 2019 年 7 月 20 日
Most of the code belongs in a method, not in a property definition.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by