How to EFFICIENTLY name multiple tables located inside a different cells

1 view (last 30 days)
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);

Accepted Answer

per isakson
per isakson on 27 Nov 2017
Edited: per isakson on 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 Comment
balandong
balandong on 27 Nov 2017
Hi Per, Thanks for the fast and awesome solution. You did what I intended to achieve. Really appreciate it.
Thank you

Sign in to comment.

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!