Effacer les filtres
Effacer les filtres

Sample関数について, 数列をランダムに生成する方法

1 vue (au cours des 30 derniers jours)
Naoki Ishibashi
Naoki Ishibashi le 7 Fév 2017
Commenté : michio le 9 Fév 2017
状態遷移関数から「天気」の数列をランダムに生成したいと考えているのですが、 以下のコードですとsample関数がうまく機能していないようなのでが、 何が問題かご存知の方教えて頂けると幸いです。
以下コード;
X_today = [ 0 1 0 ]'; % Cloudy
T = [ 8 2 0 ; 4 4 2 ; 2 6 2 ]' / 10;
X_tomorrow = sample( T * X_today );
if ( X_tomorrow(1) == 1 )
disp( 'sunny' );
elseif ( X_tomorrow(2) == 1 )
disp( 'cloudy' );
elseif ( X_tomorrow(3) == 1 )
disp( 'rainy' );
end
以下エラー;
関数または変数 'sample' が未定義です。
エラー: HW2_2 (line 5)
X_tomorrow = sample( T * X_today );

Réponses (1)

michio
michio le 8 Fév 2017
Modifié(e) : michio le 8 Fév 2017
その手のエラーメッセージは一番良く出る基本的なエラーメッセージです。 ドキュメンテーションのこのページをご覧になって対処してみて下さい。
ランダムな数列を生成する関数ですと、 rand, randi, randn, randsample など様々なものがあります。 こちらももし参考になれば。 乱数発生器
  2 commentaires
Naoki Ishibashi
Naoki Ishibashi le 8 Fév 2017
ご回答頂きありがとうございます。 調べて見たところsampleは初期状態(何もツールボックスを入れていない状態)では使えないようなのですが、sampleを使うために必要なツールボックスがなにであるのかわからないのですがご存知の方いらした教えて頂けると幸いです。 また他の関数を試してみたのですがうまくいきませんでした。
X_tomorrow = rand( T * X_today );
michio
michio le 9 Fév 2017
sampleという関数はMATLABの製品群の中には無いようですので、関数だとすればどなたかが独自に作られたものという可能性が高いですね。sample関数(もしくは変数)を使ったプログラムが Ishibashiさんの書かれたものでなければ、製作者に問い合わせるのが最も確実ですね。
数列をランダムに生成、というだけではなく X_tomorrow (出力)と T*X_today (入力)が明確に分かれば、他の関数を使って実装する道も見えてきます。

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by