How can I convert a cell array to complex double?

10 ビュー (過去 30 日間)
Luis Morales
Luis Morales 2019 年 1 月 5 日
コメント済み: Luis Morales 2019 年 1 月 5 日
Hi everyone, I am new using matlab, I did some calculation using sym in order to get a complex matrix, but I need to conver this matrix to a complex double matrix, how can I do that?
gg =
25×1 cell array
{'z(2)*2i - z(6)*2i' }
{'z(1)*2i + z(3)*2i - z(7)*2i' }
{'z(2)*2i + z(4)*2i - z(8)*2i' }
{'z(3)*2i + z(5)*2i - z(9)*2i' }
{'z(4)*2i - z(10)*2i' }
{'z(7)*2i - z(1)*2i - z(11)*2i' }
{'z(6)*2i - z(2)*2i + z(8)*2i - z(12)*2i' }
{'z(7)*2i - z(3)*2i + z(9)*2i - z(13)*2i' }
{'z(8)*2i - z(4)*2i + z(10)*2i - z(14)*2i' }
{'z(9)*2i - z(5)*2i - z(15)*2i' }
{'z(12)*2i - z(6)*2i - z(16)*2i' }
{'z(11)*2i - z(7)*2i + z(13)*2i - z(17)*2i' }
{'z(12)*2i - z(8)*2i + z(14)*2i - z(18)*2i' }
{'z(13)*2i - z(9)*2i + z(15)*2i - z(19)*2i' }
{'z(14)*2i - z(10)*2i - z(20)*2i' }
{'z(17)*2i - z(11)*2i - z(21)*2i' }
{'z(16)*2i - z(12)*2i + z(18)*2i - z(22)*2i'}
{'z(17)*2i - z(13)*2i + z(19)*2i - z(23)*2i'}
{'z(18)*2i - z(14)*2i + z(20)*2i - z(24)*2i'}
{'z(19)*2i - z(15)*2i - z(25)*2i' }
{'z(22)*2i - z(16)*2i' }
{'z(21)*2i - z(17)*2i + z(23)*2i' }
{'z(22)*2i - z(18)*2i + z(24)*2i' }
{'z(23)*2i - z(19)*2i + z(25)*2i' }
{'z(24)*2i - z(20)*2i' }
I have tried:
New = cell2mat(gg);
But I get the next error:
Error using cat
Dimensions of matrices being concatenated are not consistent.
Error in cell2mat (line 83)
m{n} = cat(1,c{:,n});
Also I have tried:
New = str2double(gg);
But I get:
Nan
I would really appreciate your help. Thank you in advance.
  4 件のコメント
Star Strider
Star Strider 2019 年 1 月 5 日
In your Symbolic Math Toolbox calculations, use the vpa function to resolve the problem of whatever ‘gg’ is, for esample:
gg_v = vpa(gg)
If you want to produce a function that the MATLAB numerical ODE solvers can use as an ODE function argument, see the documentation on the odeToVectorField and matlabFunction functions.
Luis Morales
Luis Morales 2019 年 1 月 5 日
Thank you Star, I will check it.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2019 年 1 月 5 日
In modern MATLAB (R2017b or later),
altered_gg = regexprep(gg, '\((\d+)\)', '$1');
as_sym = str2sym(altered_gg);
z_vars = symvar(as_sym);
GG = matlabFunction(as_sym, 'Vars', {z_vars(:)});
then
[T1, Z1] = ode45(GG, time, ini);
  1 件のコメント
Luis Morales
Luis Morales 2019 年 1 月 5 日
Hi Walter Roberson, thank you for your reply. Doing this I got:
Error: Too many input arguments.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Do I have to do something else?
Thank you again!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by