2014-12-02 166 views
0

我有兩個變量,targetinput和M.這兩個變量都是4x800。
例如:
可變targetinput(第一10個數據):
Variable targetinput
爲y軸,1 =正常,2 =說話,3 =笑和4 =睏倦。如何基於MatLab中的兩個變量創建表格?


變量M(第一10個數據):
enter image description here
爲y軸,1 =正常,2 =說話,3 =笑和4 =睏倦。

欲產生具有表中的x軸= targetinput和y軸= M.
實施例的表,我想生產:
enter image description here
這是第5個數據和所述的示例最終結果將是每行和每列的總數。我想要生成的表可以是MatLab中的新變量或xslx文件。
我是MatLab的新手。感謝你的幫助。

+0

你想去哪裏該表中出現?作爲屏幕上的數字?作爲一個單獨的文件(什麼類型)?請澄清 – Schorsch 2014-12-02 19:19:32

+0

如何得出結果值?你是否試圖在數組的相應元素中添加值?或者爲(Talking,Normal)單元格產生一個看起來像「1 + 1」的字符串?要麼...?我沒有看到示例輸出中的數字如何與兩個輸入對齊。 – 2014-12-02 19:22:15

+0

作爲單獨的文件。 xslx會這樣做。即時通訊嘗試數數。這將是基於輸入的總計@Schorsch – user3103158 2014-12-02 19:26:33

回答

0

的技巧是使用find有兩個輸出,0/1編碼的數據轉換成索引,然後accumarray數出現:

% determine for each column the index of the row that contains the 1 
[targetinput_row, ~] = find(targetargetinputnput); 
[M_row, ~] = find(M); 
% determine size of table 
n_M = size(M, 1); 
n_targetinput = size(targetargetinputnput, 1); 
% count number of times a pair of row indices occurs 
table = accumarray([M_row, targetinput_row], 1, [n_M n_targetinput]); 
相關問題