2013-01-12 123 views

回答

1

將字符串存儲在str中,並將您想要分配的值存儲在val中。然後您需要按照以下方式使用eval

eval([str,'= val']); 

例如,

>> str = 'X'; 
>> val = rand(5); 
>> whos 
    Name  Size   Bytes Class  Attributes 

    str  1x1     2 char     
    val  5x5    200 double    

>> eval([str,'= val']) 

X = 

    0.8147 0.0975 0.1576 0.1419 0.6557 
    0.9058 0.2785 0.9706 0.4218 0.0357 
    0.1270 0.5469 0.9572 0.9157 0.8491 
    0.9134 0.9575 0.4854 0.7922 0.9340 
    0.6324 0.9649 0.8003 0.9595 0.6787 

>> whos 
    Name  Size   Bytes Class  Attributes 

    X   5x5    200 double    
    str  1x1     2 char     
    val  5x5    200 double 
+0

感謝親愛兄弟 – Behnam

相關問題