데이터 세트의 한 열에있는 값을 기반으로 구조체에 범주화하고 저장하고자하는 데이터 세트가 있습니다.구조체 필드 이름을 숫자 배열로 작성하십시오.
%The labels I would like are based on the dataset
example_data = [repmat(100,1,100),repmat(200,1,100),repmat(300,1,100)];
data_names = unique(example_data);
%create a cell array of strings for the structure fieldnames
for i = 1:length(data_names)
cell_data_names{i}=sprintf('label_%d', data_names(i));
end
%create a cell array of data (just 0's for now)
others = num2cell(zeros(size(cell_data_names)));
%try and create the structure
data = struct(cell_data_names{:},others{:})
이 실패하고 나는 다음과 같은 오류 메시지가 얻을 :
"오류를 예를 들어, 데이터 요소 'label_100', 'label_200'또는 'label_300'나는 아래의 시도로로 분류 될 수있다 struct 사용하기 필드 이름은 문자열이어야합니다. " documentation of struct
에 따르면
(또한, 내가 위에서 할 노력하고 무엇을 달성하기 위해보다 직접적인 방법이있다?)
사용'cell2struct (다른 사람, cell_data_names을)'대신'struct'. –