Borrar filtros
Borrar filtros

How to EFFICIENTLY name multiple tables located inside a different cells

4 visualizaciones (últimos 30 días)
Dear all, The objective was to rename a table which located inside a different cell container. To make things compact, the CELLFUNC was used. However, I MATLAB output the following error
Input #2 expected to be a cell array, was char instead.
May I know what I have been missing?
Thanks in advance for any advice
The code are
load('nonChange.mat')
varname={'combination','specificity','sensitivity','accuracy','spPsn'};
ddTrans = cellfun(@array2table,'VariableNames',varname,nonChange_Cell,'UniformOutput',false);

Respuesta aceptada

per isakson
per isakson el 27 de Nov. de 2017
Editada: per isakson el 27 de Nov. de 2017
To solve the first problem, replace the cellfun statement by
ddTrans = cellfun( @(v,m) array2table(m,'VariableNames',v) ...
, varname, nonChange_Cell,'UniformOutput',false );
Next problem: the sizes don't match
>> whos nonChange_Cell varname
Name Size Bytes Class Attributes
nonChange_Cell 33x24 92993344 cell
varname 1x5 652 cell
  • What do you expect ddTrans to become?
  • Do you want to create 792 tables all with the same variable names?
If yes, try to replace the cellfun statement by
ddTrans = cellfun( @(m) array2table(m,'VariableNames',varname) ...
, nonChange_Cell,'UniformOutput',false );
inspect result
>> ddTrans{2,1}
ans =
combination specificity sensitivity accuracy spPsn
___________ ___________ ___________ ________ _______
1 0.71429 0.38462 0.53191 0.54945
2 1 0 0.44681 0.5
  1 comentario
balandong
balandong el 27 de Nov. de 2017
Hi Per, Thanks for the fast and awesome solution. You did what I intended to achieve. Really appreciate it.
Thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices 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