필터 지우기
필터 지우기

To create cells with different names in a loop

조회 수: 1 (최근 30일)
Priya
Priya 2013년 5월 25일
I have defined a cell array as follows:
names = {'joe', 'enna', 'fin'};
now in a loop I want to create empty cell arrays whose names should be 'joe' , 'enna', 'fin' respectively, instead of manually creating like follows:
joe = cell(zeros); enna = cell(zeros);fin = cell(zeros);
I have to make 50 such cell arrays in loop.
Please help how to do ?

채택된 답변

Image Analyst
Image Analyst 2013년 5월 25일

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 25일
names = {'joe', 'enna', 'fin'};
for k=1:numel(names)
eval([names{k} '=cell(5)'])
end
Creating different names is not recommended. You can create one cell array containing other cell array
  댓글 수: 5
Priya
Priya 2013년 5월 25일
@Image Analyst - Hi thanks. Actually I have around 790 datasets containing data as well as characters. Instead of working on 790 cells, would it not be better to make a single cells and sub cells in it
Image Analyst
Image Analyst 2013년 5월 25일
Priya, the best way would be to have a cell array, not a single cell, but a whole array of cells. The row in the array would represent the dataset (1 through 790) and the column would be the data for that data set (the various numbers and strings associated with that dataset). See the FAQ for a good description of cells: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by