フィルターのクリア

How to EFFICIENTLY name multiple tables located inside a different cells

4 ビュー (過去 30 日間)
balandong
balandong 2017 年 11 月 27 日
コメント済み: balandong 2017 年 11 月 27 日
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 件のコメント
Stephen23
Stephen23 2017 年 11 月 27 日
@balandong: you should also load into a variable, rather than directly into the workspace.
balandong
balandong 2017 年 11 月 27 日
Thanks for the advice, appreciate it

サインインしてコメントする。

採用された回答

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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by