2010-06-04 41 views

回答

3

因爲它是一個有點不清楚你想要什麼,這裏有一些選擇:

  • 要進行1000×4的矩陣,其中每行是'TEST',你可以使用函數REPMAT

    M = repmat('TEST',1000,1); 
    
  • 要添加到'TEST'字符的1000乘4矩陣的每行的末端,則可以使用該函數STRCAT

    M = repmat('a',1000,4); %# Sample matrix filled with 'a' 
    M = strcat(M,'TEST'); %# Append 'TEST' to each row of M 
    
  • 如果您的1000 * 4矩陣是一個數字數組而不是一個字符數組,您將不得不使用cell arrays來組合不同類型的數據。這裏是你可以做到這一點的一種方法:

    M = rand(1000,4); %# A matrix of random numeric values 
    M = num2cell(M,2); %# Put each row of M in a cell, making 
            %# a 1000-by-1 cell array 
    M(:,2) = {'TEST'}; %# Add a second column to the cell array, 
            %# where each cell contains 'TEST' 
    
0

矩陣不能包含一個字符串(如「TEST」)。 你需要使用一個cell array

0

如果這是一個現有的矩陣單元串M

M(:,end+1) = {'TEST'}; 
相關問題