1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

dSPACEAdvent Calendar 2024

Day 24

ControlDeskで取得したデータをMATLABでデータ処理

Posted at

1. はじめに

ControlDeskでエクスポートしたcsvをサクッとグラフにするためのMATALBのmファイルの書き方を説明します.
何万行もあるデータをExcelで処理するのはナンセンスです.
今回はファイルから計測値の部分を抽出,変数に格納,グラフ描画までを説明します.

2. 記述

% ------------------------------------------------------------------------
% + Automatic graph drawing program for dSPACE ControlDesk
% +  + filter function
% + version: 6.0
% + date: 2024/01/04
% + creator: Ryunosuke Sawahashi
% + 
% + Confirmed simulink version: R2022a, R2023b
% + ※javaが必要
% ------------------------------------------------------------------------

%% データ準備 (ファイルから計測値のみ抽出)
% Extract only the measured values.
% Extract header and values range 2行除外
T = readtable(append(path, file), 'NumHeaderLines', 0);

% Edit the header names.
%T.Properties.VariableNames("Var2") = "time";
% Extract all header names
oldHeaderNames = T.Properties.VariableNames;
% 可読性向上
newHeaderNames = T.Properties.VariableNames;
T = renamevars(T, oldHeaderNames, newHeaderNames);
%head(T)

% NOTE: 記号はすべてアンダーバー(_)になる
% 例) current_[A] -> current__A_
%   1      2          3          4
%[time, signal_A_, signal_B_, signal_C_, ...]

%% plot
paste_destination = 'word';
if contains(paste_destination, 'word')
    font_name = 'Times New Roman';
else
    font_name = 'Segoe UI';
end
% d = listfonts     % 使えるフォント一覧
font_size = 12;
% TODO: javaが使えない場合のエラー処理
toolkit = java.awt.Toolkit.getDefaultToolkit();
scr_size = toolkit.getScreenSize();     % display size
jframe = javax.swing.JFrame;
insets = toolkit.getScreenInsets(jframe.getGraphicsConfiguration());    % taskbar size

f1 = figure('Name', 'Unit Data');
f1.Position = [0, insets.bottom, 1920, 720];

ax = gca;

plot(t, T{:, "current__A_"}, "black", ...
     t, T{:, "curr_A__AVE_"}, "red");
xlabel('Time [s]', 'FontSize', font_size, 'FontName', font_name);
ylabel('Current [mA]', 'FontSize', font_size, 'FontName', font_name);
xlim([xRangeMinTime xRangeMaxTime]);
ylim([0 250]);
gridFunc(ax);

サンプルデータも準備

3. 注意事項

ControlDeskの環境によってcsvファイルに記載される情報量が変わるので注意が必要です.
要は,このセルにこの情報が確実に入っている保証がないということです.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?