[問題] 陣列迴圈處理已回收
各位前輩,小弟處理Oracle的DB資料要將其轉為分析格式
ex. Oracle格式 先讀入Matlab為cell_array內容如下
CustomerA, item1 , 10
CustomerA, item2 , 20
CustomerA, item4 , 50
CustomerB, item1 , 20
CustomerB, item3 , 40
CustomerB, item4 , 20
CustomerC, item1 , 30
CustomerC, item2 , 50
ex. 要湊的分析格式final_cell
item1 item2 item3 item4
CustomerA 10 20 0 50
CustomerB 20 0 40 20
CustomerC 30 50 0 0
% 小弟的想法如下
unique_customer=unique(cell_array(:,1));
unique_item=unique(cell_array(:,2));
final_cell=cell(length(unique_customer),length(unique_item));
for i=1:size(unique_customer,1)
for j=1:size(unique_customer,1) % 請忽略找不到的情況..僅表達困難處
final_cell{i,j}=cell_array(find(strcmp(cell_array(:,2),'item1')==1),3);
end
end
% 這樣的確可以做到,但是當資料筆數與欄位多時,整個效率差
不知道各位前輩有沒有什麼好方法呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.116.106.135
※ 編輯: jirolee 來自: 122.116.106.135 (09/02 21:43)
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 3 篇):
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章