コマンドウィンドウに収まらない長い文字列を取得する方法
21 views (last 30 days)
Show older comments
コマンドウィンドウに収まらない長い文字列を取得する方法を知りたいです。
複雑な連立方程式を解いた計算結果の文字列がとても長くなりコマンドウィンドウに収まりません。
全てをコマンドウィンドウに表示するなど、計算結果の文字列を取得する方法はありますか?
計算結果をsimulink内のmatlab fcnで使うためにsave関数やload関数を試みたのですが、計算結果内で用いる変数を毎回宣言するためかシミュレーションにとても時間がかかってしまいます。
計算結果の文字列をmatlab fcn内で直接用いたいと考えています。
以下は例です。
例では簡単のため、計算結果をtest1,2,3として表示できる形にしています。
clear
format short
syms a b c d e f g h
%計算結果代用
%実際はコマンドウィンドウに収まらない長さです。
test1 = a+b+c+d;
test2 = e*f*g;
test3 = h^2-a*b;
%fun_loadtest(x)への入力
u = [1
1]
x0=[1
1
1]
x1=[1
1
1]
save('load_test.mat','test1','test2','test3')
matlab fcn内は以下のようになります。
この関数ですと計算に時間がかかります。
function y = fun_loadtest(x)
format short
%test1,2,3の呼び出し
load('load_test.mat')
%ここからが処理を重くしている?
syms a b c d e f g h
a = x(1) ;
b = x(2) ;
c = x(3) ;
d = x(4) ;
e = x(5) ;
f = x(6) ;
g = x(7) ;
h = x(8) ;
%呼び出したtest1,2,3にx(1),...を代入した結果
x = [subs(test1)
subs(test2)
subs(test3)] ;
%出力
y = double(x);
上の関数を以下のようにすると計算時間が短くなります。
function y = fun_loadtest(x)
format short
test1 = x(1)+x(2)+x(3)+x(4);
test2 = x(5)*x(6)*x(7);
test3 = x(8)^2-x(1)*x(2);
x = [test1
test2
test3] ;
y = double(x);
入力を直接x(1),x(2),...として使いたいのですが、長い文字列ですとその全容が分からず、変えることができない状態です。
助言いただければ幸いです。
0 Comments
Accepted Answer
Etsuo Maeda
on 24 Mar 2020
matlabFunction: https://jp.mathworks.com/help/symbolic/matlabfunction.html
を使って、シンボリック式を関数ハンドルか関数ファイルに変換してしまえばいいと思いますが。。。
HTH
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!