Automated variable name assignment

3 ビュー (過去 30 日間)
Mario
Mario 2016 年 11 月 2 日
コメント済み: Mario 2016 年 11 月 2 日
I have large cells that contain experimental data. (Up to 100000 entries with 2x2000 matricies each) On these large cells I run different cluster scripts that split these large cells into sub-cells (normally between 2 and 10 sub-cells) I then save these sub-cells and run different analysis routines on them. Is there a way to automatically name and save these subcells?
For example: I have a main_cell, split it up into 3 subcells, call them "subcell_1, subcell_2 and subcell_3" and then save them as subcell_1.mat etc. So far I have to do this manually or with this rather ugly "try and catch" approach (It is also limited because I cannot adapt the subcell's name automatically):
try
subcell_1 = main_cell(:,idx==1);
save('subcell_1.mat','subcell_1');
subcell_2 = main_cell(:,idx==2);
save('subcell_2.mat','subcell_2');
catch
end
I know apparently it is recommended not to use dynamic variable naming, but for my specific situation I cannot think of another way without completly restructuring my analysis concept and/or dragging huge data files through my analysis.
  2 件のコメント
KSSV
KSSV 2016 年 11 月 2 日
Instead of that naming convention...you can follow:
C = cell(1,3) ;
C{1} % will be subcell_1
c{2} % will be subcell 2
c{3} % will be subcell 3
Mario
Mario 2016 年 11 月 2 日
Thanks for the answer! I know I am going for a "bad" convention but I would really prefer not to drag the whole cell through the analysis. They can be up to one GB in size and it takes forever to load cells like this.
Plus, it is more clearly arranged if I can split up cells into few appropriatly named subcells in subfolders because I typically use multiple analysis and clustering steps in changing orders and if I keep everything in one cell it quickly gets messy.

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

採用された回答

Walter Roberson
Walter Roberson 2016 年 11 月 2 日
  3 件のコメント
Walter Roberson
Walter Roberson 2016 年 11 月 2 日
Use dynamic field names of a struct . save() the struct using the -struct flag to save(). Each field in the struct will become a variable in the .mat file.
Mario
Mario 2016 年 11 月 2 日
Yes, that's it! Thank you both!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBehavior and Psychophysics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by