필터 지우기
필터 지우기

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 CenterFile Exchange에서 Large 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