2017-10-14 4 views
0

에서 배열을 만들 수 있습니다.matlab에/시뮬링크 :</p> <p>내가 매트랩 테이블에 데이터베이스에서 사실 테이블을 수입하고 있습니다 : 크게 다음과 같은 문제에 약간의 도움을 주셔서 감사합니다겠습니까 팩트 테이블

SeqNo  Cat Observation 
1   A  0.3 
1   B  0.5 
1   C  0.6 
2   B  0.9 
2   C  1.0 
3   A  1.2 
3   C  1.5 

내가 사실 테이블을 delinearize과 열을 나타내는 범주 매트릭스 (또는 다른 테이블),이 같은 즉, 무언가를 창조하기 위해 지금 필요한 다음과 같이 사실 테이블은 여러 범주에 걸쳐 관찰의 순서로 구성 :

Seq A  B  C 
1  0.3 0.5 0.6 
2  NaN 0.9 1.0 
3  1.2 NaN 1.5 

나는 findgroup 및 분할 신청 결합, 워크 플로우를하지만 행운 주위했다. 결국 SPSS Modeler를 사용하여 가져 오기를 위해 제대로 구조화 된 CSV 파일을 만들지 만 Matlab 또는 Simulink에서이를 완벽하게 수행해야합니다.

어떤 도움이 가장 환영받을 것입니다.

+0

[관련 (https://stackoverflow.com/questions/46682751/efficient-ways-to-append-new-data-in-matlab-with-example -code/46686878 # 46686878) – rahnema1

+0

Simulink와 어떤 관련이 있습니까? –

답변

1
%Import table 
T=readtable('excelTable.xlsx'); 
obs_Array=T.Observation; 
%Extract unique elements from SeqNo column 
seqNo_values=(unique(T.SeqNo)); 
%Extract unique elements from Cat column 
cat_values=(unique(T.Cat)); 

%Notice that the elements in seqNo_values 
%already specify the row of your new matrix 

%The index of each element in cat_values 
%does the same thing for the columns of your new matrix. 

numRows=numel(seqNo_values); 
numCols=numel(cat_values); 

%Initialize a new, NaN matrix: 
reformatted_matrix=NaN(numRows,numCols); 

%magic numbers: 
seqNo_ColNum=1; 
cat_ColNum=2; 

for i=1:numel(obs_Array) 
    target_row=T(i,seqNo_ColNum); 
    %convert to array for ease of indexing 
    target_row=table2array(target_row); 

    %convert to array for ease of indexing 
    target_cat=table2array(T(i,cat_ColNum)); 
    target_cat=cell2mat(target_cat); 

    target_col=find([cat_values{:}] == target_cat); 
    reformatted_matrix(target_row,target_col)=obs_Array(i); 
end 
    reformatted_matrix 

출력 :

reformatted_matrix = 

    0.3000 0.5000 0.6000 
     NaN 0.9000 1.0000 
    1.2000  NaN 1.5000