実行結果取得方法について

9 views (last 30 days)
kai egami
kai egami on 29 Jan 2020
Answered: kai egami on 30 Jan 2020
こんにちは
カルマンフィルタの勉強をするためにMATLABを用いようとしています。
以下のURLのサイトにあるMATLABにおけるカルマンフィルタのサンプルを実行してみました。
グラフの作成は行えますが、プロットされた複数の出力データを取得方法がわかりません。
方法がわかる方、レクチャーしてくだされば助かります。
もしくは、グラフからデータを取得する方法もわかればありがたいです。
よろしくお願いいたします。kalman.png

Answers (2)

Toshinobu Shintai
Toshinobu Shintai on 29 Jan 2020
ObjTrack.mという関数スクリプト内でプロットが行われているようですので、計算結果を関数から出力させればよいです。
以下のように改造しました。
% Copyright 2010 The MathWorks, Inc.
function [y_out, z_out] = ObjTrack(position)
%#codegen
% First, setup the figure
numPts = 300; % Process and plot 300 samples
figure;hold;grid; % Prepare plot window
y_out = zeros(2, numPts);
z_out = zeros(2, numPts);
% Main loop
for idx = 1: numPts
z = position(:,idx); % Get the input data
y = kalmanfilter(z); % Call Kalman filter to estimate the position
plot_trajectory(z,y); % Plot the results
y_out(:, idx) = y;
z_out(:, idx) = z;
end
hold;
end % of the function
その後、CCodeGenerationForAMATLABKalmanFilteringAlgorithmExample.mlxの13行目を
[y, z] = ObjTrack(position)
とすることでベースワークスペースに数値データを記録することができます。

kai egami
kai egami on 30 Jan 2020
詳しい解説をして頂き、大変ありがたいです。
ObjTrack.mという関数スクリプト内で設定する方法を試し、自分の想定する動作を実現することが出来ました。
ありがとうございます。

Community Treasure Hunt

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

Start Hunting!