renaming a cell
31 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
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 个评论
Fangjun Jiang
2011-12-1
>> s=cell2struct(File1,naming,2)
s =
data1: [19x1 double]
data2: [19x1 double]
data3: [19x1 double]
data4: [18x1 double]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!