MATLAB CoderによるC言語への変換について

69 visualizaciones (últimos 30 días)
Yuu
Yuu el 25 de En. de 2020
Comentada: Yuu el 30 de En. de 2020
以下のMATLAB言語をC言語に変換したいと考えています。MATLAB CoderによるCコード生成のガイドを拝見しましたが、入力引数の設定が理解できませんでした。
また、サポートされていないMATLAB関数(tableや構造体)からサポートされているものへの修正方法も分かりませんでした。
以下のコードをどのように修正するとC言語に変換できるのか、ご教授の程よろしくお願いいたします。
% テーブルdictionaryの作成
T_d = readtable('list.csv','ReadVariableNames',false);
% 単語の列を抽出
T_d = T_d(:,{'Var2'});
T_d.Properties.VariableNames = {'Tango'};
% 重複を消す(一応)
[~,ia] = unique(T_d.Tango);
T_d = T_d(ia,:);
% 始めと終わりの文字の抽出
T_d.Start = cellfun(@(x) {x(1)}, T_d.Tango);
T_d.End = cellfun(@(x) {x(end)}, T_d.Tango);
% 最後が長音の文字をピックアップし、一文字前の文字を抽出
Nobasu = strcmp(T_d.End,'ー');
T_d.End(Nobasu) = cellfun(@(x) {x(end-1)}, T_d.Tango(Nobasu));
% 使った単語を記録するための列(com)
T_d.Used = false(height(T_d),1);
% しりとりの初めの文字をランダムで選択
pt = randi(height(T_d));
fprintf(' Com : %s \n',T_d.Tango{pt});
T_d.Used(pt) = true;
% =====ユーザーが入力した単語を格納するテーブルの仕様作成=====
% ※テーブルT_dと同じ仕様=ユーザー入力回数は有限
varNames = T_d.Properties.VariableNames;
T_Input = table(...
'Size', [0 4],...
'VariableTypes',{'cell','cell','cell','logical'},...
'VariableNames',varNames);
% ==========しりとりを行うプログラム=========
while true
% COMが選択した単語の最後の文字を抽出し「ン」なら終了(comの負け)
curChar = T_d.End(pt);
if strcmp(curChar,'ン')
disp(' Com : I could accept this Loss. ')
% errordlg(' You Beat Me ! ',' Congratulation! ');
break;
end
% ユーザーによる単語の入力フェーズ
prompt = ' Your turn : ';
UI= input(prompt,'s'); % ユーザーによるコマンド入力
% しりとりのルールに則っていなかったら終了(ユーザーの負け)
if ~strcmp(UI(1), curChar)
% errordlg(' You Lose... ',' Violation! ');
break;
end
% ユーザーが入力した単語の最後の文字を抽出し「ン」なら終了(ユーザーの負け)
curChar = UI(end);
if strcmp(curChar,'ン')
% errordlg(' You Lose... ',' Violation! ');
end
% ユーザーが入力した単語をテーブルに格納
if strcmp(UI(end),'ー')
T_Input = [T_Input; {UI, UI(1), UI(end-1), true}]; %#ok
else
T_Input = [T_Input; {UI, UI(1), UI(end), true}]; %#ok
end
% 一度使用した単語以外を探す
pt = find(strcmp(T_Input.End(end),T_d.Start) & ~T_d.Used);
if isempty(pt)
disp(' Com : I could accept this Loss. ');
break;
end
pt = pt(randi(numel(pt))); %"ン"で終わる単語を選ぶ確率の調整必要
fprintf(' Com : %s \n',T_d.Tango{pt});
T_d.Used(pt) = true;
end

Respuestas (1)

michio
michio el 29 de En. de 2020
まず、C コード生成される対象は関数(スクリプトではなく)なので、
function output = functioname(inputs)
end
という形で関数化する必要があります。
既に確認されているかもしれませんが「C/C++ コード生成でサポートされている MATLAB 言語機能」も一読いただければと思います。また、対応している関数一覧は
にあります。ここに載っていない関数は、載っている関数で代用する必要があります。例えばデータの読み込みは
を参照ください。
具体的にどの関数(コマンド)の書換方法・・ということであれば、また別途質問を投げて頂ければヒントを貰えると思いますので、よろしくお願いいたします。
  1 comentario
Yuu
Yuu el 30 de En. de 2020
ご回答いただきありがとうございます。
頂いたコメントを参考にしてもう一度内容を改めて質問いたします。

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!