2013-10-27 96 views
0

我正在嘗試用數據創建多維數組。 我有一個17x10x1024空單元陣列:MATLAB:將矢量分配給多維單元陣列

C=cell(length(data(1,:)),10,1024); 

% length(data(1,:) = 17 

然後我計算(在while循環(17次))載體,其是1024x1:

value = data(:,i) + randn(size(t))*noise_out; 

現在我要分配的值這個矢量到陣列中,以這樣的方式即:

'Name of Signal'     [] [] [] [] [] [] [] [] [] 
    'in1'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'out1'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'in2'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'out2'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'in3'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'out3'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'in4'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'out4'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'in5'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'out5'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'in6'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'out6'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'in7'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'out7'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'in8'    [1024x1 double] [] [] [] [] [] [] [] [] 
    'out8'    [1024x1 double] [] [] [] [] [] [] [] [] 

我使用下面的:

C(i,2,:) = {value}; 

% i is the number of loop from 2 to 17 

,但問題是,我實際上得到一個字符串'[1024x1雙]',而不是矢量的實際值。

任何想法?

回答

2

你想要得到的東西似乎對我來說並不合理,因爲你在單元格中有很多單值,而你更願意使用矢量。

我提出三個選項:

C=cell(length(data(1,:)),10); 
C(i,2) = value; 

,讓你在一列您的姓名和細胞對細胞矩陣與向量信號,在其他列

但實際上我建議不要將名稱和信號一起存儲在單元陣列中。因此,如果你想要一個三維矩陣與你的信號保持名稱分開,並創建:

C = zeros(length(data(1,:)),10,1024); 
C(i,2,:) = value; 

或考慮使用結構;

signal(1).name = 'in1' 
signal(1).values = value 
signal(2).name = 'out1' 
signal(2).values = value2 

這些都只是想法,我還沒有嘗試過,因爲你沒有提供足夠的信息。