samplefun
クラス: matlab.unittest.measurement.MeasurementResult
名前空間: matlab.unittest.measurement
配列 MeasurementResult
のサンプル全体に関数を適用
構文
[B1,...,Bm] = samplefun(fh,R)
[B1,...,Bm] = samplefun(fh,R,'UniformOutput',tf)
説明
入力引数
配列 MeasurementResult
の各要素のサンプルにまたがって適用する関数。関数ハンドルとして指定します。
テスト スイートで測定実験を実行した結果。配列 MeasurementResult
として指定します。
fh
が一様な値を返すかどうかのインジケーター。true
または false
として指定します。tf
の既定値は true
であり、これは fh
が、連結して配列にできるスカラー値を返すことを示します。tf
が false
の場合、fh
の出力は異なるサイズとデータ型をもつことができます。samplefun
は、これらの一様でない出力を cell 配列に出力します。
例
現在の作業フォルダーに、さまざまな事前割り当てメソッドを比較するクラスベースのテスト preallocationTest.m
を作成します。
classdef preallocationTest < matlab.perftest.TestCase methods(Test) function testOnes(testCase) x = ones(1,1e7); end function testIndexingWithVariable(testCase) id = 1:1e7; x(id) = 1; end function testIndexingOnLHS(testCase) x(1:1e7) = 1; end function testForLoop(testCase) for i=1:1e7 x(i) = 1; end end end end
テスト スイートを作成します。
suite = testsuite('preallocationTest');
可変時間実験を作成し、テストを実行します。
import matlab.perftest.TimeExperiment
experiment = TimeExperiment.limitingSamplingError;
R = run(experiment,suite);
Running preallocationTest .......... .......... .......... ......Warning: Target Relative Margin of Error not met after running the MaxSamples for preallocationTest/testOnes. .... .......... .......... .......... .......... ..... Done preallocationTest __________
テスト要素ごとに、サンプルの平均時間を特定します。
M = samplefun(@mean,R)
M = 0.0350 0.1351 0.0789 0.7337
テスト要素ごとに、最小時間と、最小時間のインデックスを特定します。
[M,I] = samplefun(@min,R)
M = 0.0258 0.1169 0.0691 0.6531 I = 27 3 1 1
現在の作業フォルダーに、さまざまな事前割り当てメソッドを比較するクラスベースのテスト preallocationTest.m
を作成します。
classdef preallocationTest < matlab.perftest.TestCase methods(Test) function testOnes(testCase) x = ones(1,1e7); end function testIndexingWithVariable(testCase) id = 1:1e7; x(id) = 1; end function testIndexingOnLHS(testCase) x(1:1e7) = 1; end function testForLoop(testCase) for i=1:1e7 x(i) = 1; end end end end
テスト スイートを作成します。
suite = testsuite('preallocationTest');
サンプル測定が 26 件の固定回数時間実験を作成し、テストを実行します。
import matlab.perftest.TimeExperiment
experiment = TimeExperiment.withFixedSampleSize(26);
R = run(experiment,suite);
Running preallocationTest .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .... Done preallocationTest __________
現在の作業フォルダーで関数 customSampleFun
を作成します。この関数は 26 件のサンプルのそれぞれの平均値を計算し、この平均値をミリ秒単位に変換し、平均時間が速いか遅いかを示す文字ベクトルを返します。
function [mean_ms,speed] = customSampleFun(S) threshold_ms = 100; mean_ms = mean(S)*1e3; if mean_ms < threshold_ms speed = 'fast'; else speed = 'slow'; end end
customSampleFun
を配列 MeasurementResult
の各要素に適用します。文字ベクトルはスカラーではないため、UniformOutput
を false に指定します。
[mean_ms,speed] = samplefun(@customSampleFun,R,'UniformOutput',false)
mean_ms = 1×4 cell array [30.9500] [142.7037] [83.9830] [806.3446] speed = 1×4 cell array 'fast' 'slow' 'fast' 'slow'
バージョン履歴
R2017a で導入
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)