# how can i change cell array to matrix

2 visualizaciones (últimos 30 días)
Abebe kebede el 16 de Mzo. de 2015
Respondida: Abebe kebede el 17 de Mzo. de 2015
I have excel mixed file and used [T,M,dat]=xlsread('Mol.xlsx')to import to matlab
dat= 'A' [12] [-20] [-75] [66] 'B' [9] [-10] [-50] [55] 'C' [15] [-25] [10 ] [45] 'D' [14] [-15] [5] [20]
I want to remove row if the value of column 3 is >= -15. so i used the following criteria, dat(dat(:,3)>=-15,:)=[] but i get the following error Undefined function or method 'ge' for input arguments of type 'cell'. how can i solve this problem?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Guillaume el 16 de Mzo. de 2015
Since you have mixed data types you can't convert the cell array into a matrix. You could just operate on the numeric matrix T and text matrix M with:
rowstodelete = T(:, 3) >= -15;
T(rowstodelete, :) = [];
M(rowstodelete, :) = [];
dat(rowstodelete, :) = [];
Simpler, would be to use a table which can handle mixed data types and has a more intuitive syntax than cell arrays. It's also dead easy to import excel data into a table:
t(t(:, 3) >= -15, :) = [] %delete rows for which column 3 is >=-15
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Más respuestas (2)

Giorgos Papakonstantinou el 16 de Mzo. de 2015
Editada: Giorgos Papakonstantinou el 16 de Mzo. de 2015
You can do the following to find which values are >=-15 :
dat= {'A' [12] [-20] [-75] [66] 'B' [9] [-10] [-50] [55] 'C' [15] [-25] [10 ] [45] 'D' [14] [-15] [5] [20]};
dat(cellfun(@(x) x>=-15 & ~ischar(x), dat)) = [];
Of course the result will be again a cell.
However, the T output argument from xlsread will be be of class double so there will be no need to go through the cellfun command.
You can see this with a minimum example:
values = {'A' [12] [-20] [-75] [66] 'B' [9] [-10] [-50] [55] 'C' [15] [-25] [10] [45] 'D' [14] [-15] [5] [20]};
xlswrite('myExample.xlsx',values);
filename = 'myExample.xlsx';
Then:
T =
12 -20 -75 66 NaN 9 -10 -50 55 NaN 15 -25 10 45 NaN 14 -15 5 20
If you want simply to remove them:
T(>=-15) = [];
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Abebe kebede el 17 de Mzo. de 2015
Thank you very much guys.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Spreadsheets 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