Effacer les filtres
Effacer les filtres

How to EFFICIENTLY name multiple tables located inside a different cells

4 vues (au cours des 30 derniers jours)
balandong
balandong le 27 Nov 2017
Commenté : balandong le 27 Nov 2017
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);
  2 commentaires
Stephen23
Stephen23 le 27 Nov 2017
@balandong: you should also load into a variable, rather than directly into the workspace.
balandong
balandong le 27 Nov 2017
Thanks for the advice, appreciate it

Connectez-vous pour commenter.

Réponse acceptée

per isakson
per isakson le 27 Nov 2017
Modifié(e) : per isakson le 27 Nov 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 commentaire
balandong
balandong le 27 Nov 2017
Hi Per, Thanks for the fast and awesome solution. You did what I intended to achieve. Really appreciate it.
Thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by