How can I convert a cell array to complex double?

6 visualizaciones (últimos 30 días)
Luis Morales
Luis Morales el 5 de En. de 2019
Comentada: Luis Morales el 5 de En. de 2019
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 comentarios
Star Strider
Star Strider el 5 de En. de 2019
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 el 5 de En. de 2019
Thank you Star, I will check it.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de En. de 2019
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 comentario
Luis Morales
Luis Morales el 5 de En. de 2019
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!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by