2010-06-04 43 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'}; 
相关问题