Borrar filtros
Borrar filtros

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

8 visualizaciones (últimos 30 días)
Naoki Ishibashi
Naoki Ishibashi el 7 de Feb. de 2017
Comentada: michio el 9 de Feb. de 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 );

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by