0

I am trying to compute the code seen below, in a more clever way, using MatLAB:

f=zeros(5,2) %Values irrelevant.
y = {'A1', 'B1'; 
     f(1,1) f(1,2); 
     f(2,1) f(2,2); 
     f(3,1) f(3,2); 
     f(4,1) f(4,2); 
     f(5,1) f(5,2)};  

What I get out is the f matrix with the text of A1 and B1 above the two vectors.

I suppose there is a simpler way to write this, for more complex purposing, but I've tried any combination of parenthesis, brackets and curly brackets, num2str that I could think of.

Any suggestions?

4

1 に答える 1

2

最も簡単な解決策はnum2cell、結果を使用して文字列と連結することです。

y = [{'A1', 'B1'}; num2cell(f)];

>> f = reshape(1:10, 2, [])';
>> y = [{'A1', 'B1'}; num2cell(f)]

y =
    'A1'    'B1'
    [ 1]    [ 2]
    [ 3]    [ 4]
    [ 5]    [ 6]
    [ 7]    [ 8]
    [ 9]    [10]
于 2013-04-23T16:57:42.640 に答える