Convert Cell Array into equation
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ga97cad
el 21 de Oct. de 2021
Comentada: Stephen23
el 21 de Oct. de 2021
Hi everyone!
I have a simple question and I have already been looking for an answer that suits my problem here in the community but haven't found anything yet so here I go:
I am reading a .csv file with the function readtable and it works perfectly fine, but there is one column were an quation like this is written: 19*32 for example in each cell. What i want is Matlab to just calculate that equation for each cell of the array, to just get one number. For example for the equation above it would be 608. Matlab reads this column as a Cell Array and I already tried the cell2mat function, but that didn't help me unfortunetly....
I have attached a file with an exmaple of the column that I want to solve.
Thank you for your help and best regards from germany
Lukas
1 comentario
Stephen23
el 21 de Oct. de 2021
Slightly more robust would be to use STR2NUM:
T = readtable('matlab_example.csv','Delimiter',',');
V = cellfun(@str2num, T.flaeche_li_2)
Respuesta aceptada
Voss
el 21 de Oct. de 2021
If C is a cell array containing a MATLAB expression in each cell, then the following code will evaluate the expressions and return a vector of results:
V = cellfun(@(x)eval(x),C);
Más respuestas (1)
Dave B
el 21 de Oct. de 2021
I think you could use a combination of cellfun (to run on each cell) and eval (to evaluate the expression):
a=readtable('matlab_example.csv','Delimiter',',');
a.evaluated=cellfun(@eval,a.flaeche_li_2);
head(a)
Ver también
Categorías
Más información sobre Logical 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!