フィルターのクリア

renaming a cell

31 ビュー (過去 30 日間)
ricco
ricco 2011 年 12 月 1 日
I have a 1x4 cell called 'naming' which contain names of 4 data sets e.g. 'data1', 'data2' etc...
I have another 1x4 cell called 'File1' which contains 4 cells e.g. 19x1 cell, 19x1 cell, 19x1 cell, and a 18x1 cell.
All I would like to do is to use the names in 'naming' as the name of each cell in 'File1'. So, instead of having 19x1 cell etc... I would have 'data1' and so on. It seems straight forward but I attempted to use
New_File=struct(naming(1),File1(1)...)
But it doesnt work as it requires a string input, which I thought 'naming(1)' would be a string?
cheers

回答 (2 件)

David Young
David Young 2011 年 12 月 1 日
naming(1)
is a cell, but
naming{1}
is a string.
EDIT: added example
>> naming = {'data1', 'data2', 'data3', 'data4'};
>> File1 = {rand(19,1), rand(19,1), rand(19,1), rand(18,1)};
>> New_File = struct(naming{1}, File1{1}, naming{2}, File1{2}, naming{3}, File1{3}, naming{4}, File1{4});
>> New_File
New_File =
data1: [19x1 double]
data2: [19x1 double]
data3: [19x1 double]
data4: [18x1 double]
You can simplify this further. Instead of calling struct, use
New_File = cell2struct(File1, naming, 2);
  2 件のコメント
ricco
ricco 2011 年 12 月 1 日
I've tried this, it says that it is an invalid field name! any advice?
David Young
David Young 2011 年 12 月 1 日
Works for me! I've put example code in my answer to show how it goes.

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


Fangjun Jiang
Fangjun Jiang 2011 年 12 月 1 日
>> s=cell2struct(File1,naming,2)
s =
data1: [19x1 double]
data2: [19x1 double]
data3: [19x1 double]
data4: [18x1 double]

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by