2016-12-22 6 views
0

J'ai un problème avec la ligne "P_dot_ij_om_ + ii (i, 1) = P_dot_ij (k, 2);" j'ai fondamentalement déclaré la matrice P_dot_ij_om_1 = [] de 1 à 0 et à la ligne suivante.comment accéder aux variables déclarées sous forme de chaîne dans scilab

Je voudrais entrer des données, par ex. P_dot_ij_om_ + ii (i, 1) = P_dot_ij (k, 2); où ii est un nombre. Quelle est la bonne expression?


rows=round(k/360); 
i=1; 
ii=1; 
k=1; 
while ii <= rows 

    Pdot_names(ii,1)=string("P_dot_ij_om_"+ string(ii)); 

    disp(Pdot_names(ii)) 
    execstr(Pdot_names(ii)+'=[]');   // declare indexed matrix 

    while i<361 

     P_dot_ij_om_+ii(i,1)=P_dot_ij(k,2); 
     // P_dot_ij_om_+ii(i,2)=P_dot_ij(k,3); 

     disp(k) 
     k=k+1; 
     i=i+1; 
    end 
ii=ii+1; 


end 

+0

Bienvenue dans Stackoverflow! Si vous avez la bonne réponse à votre question, n'oubliez pas de 'Accepter'. – Attila

Répondre

0

Le code ci-dessous fonctionne, mais en général, il est conseillé de ne pas créer des variables de chaîne. Il existe des alternatives beaucoup plus rapides et plus faciles à mettre en œuvre, voir par ex. ce fil: How can I create variables Ai in loop in scilab, where i=1..10

rows = 2; 
P_dot_ij = [10,20,30;11,21,31;12,22,32]; 
i=1; 
ii=1; 
k=1; 
while ii <= rows 

    //Pdot_names(ii,1)=string("P_dot_ij_om_"+ string(ii)); The firs 'string' is unnecessary 
    Pdot_names(ii,1)="P_dot_ij_om_"+string(ii);  

    disp(Pdot_names(ii)) 
    execstr(Pdot_names(ii)+'=[]');   // declare indexed matrix 

    while i<4 

     //P_dot_ij_om_+ii(i,1)=P_dot_ij(k,2); 
     execstr("P_dot_ij_om_"+string(ii)+"("+string(i)+",1)=P_dot_ij("+string(k)+",2)");   // P_dot_ij_om_+ii(i,2)=P_dot_ij(k,3); 
     execstr("P_dot_ij_om_"+string(ii)+"("+string(i)+",2)=P_dot_ij("+string(k)+",3)"); 

     disp(k) 
     k=k+1; 
     i=i+1; 
    end 
    ii=ii+1; 
end 

disp(P_dot_ij_om_1,"P_dot_ij_om_1"); 
disp(P_dot_ij_om_1,"P_dot_ij_om_2"); 

Et la prochaine fois s'il vous plaît publier des exemples de code selfcontained, parce que sinon je ne peux que deviner ce qui est k et P_dot_ij.