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

6 visualizzazioni (ultimi 30 giorni)
Naoki Ishibashi
Naoki Ishibashi il 7 Feb 2017
Commentato: michio il 9 Feb 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 );

Risposte (1)

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

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by