How to EFFICIENTLY name multiple tables located inside a different cells

4 次查看(过去 30 天)
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);

采纳的回答

per isakson
per isakson 2017-11-27
编辑:per isakson 2017-11-27
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 个评论
balandong
balandong 2017-11-27
Hi Per, Thanks for the fast and awesome solution. You did what I intended to achieve. Really appreciate it.
Thank you

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by