Effacer les filtres
Effacer les filtres

How to create matrices and change matrix names in a for loop (Sprint and Eval) ?

1 vue (au cours des 30 derniers jours)
ARS
ARS le 7 Juin 2013
Hi,
I have the following loop.
periods=28
*for z=1:periods
Period(z)Return{s,j}= open - close
FReturnLMS{s,k} = Period(z)Return{s,j}
end;*
All loops are working except the z in * Period(z)Return{s,j}*. Please ignore s and j & k as they work fine. Only evaluating z is an issue. I am having trouble in deploying sprintf and eval.
Also please tell if there is a detailed source to understand the usage of Sprintf and eval.
All help will be appreciated.
Regards,
AMD.

Réponse acceptée

Iain
Iain le 7 Juin 2013
Period(z)Return{s,j} looks like a structure, but it seems to be missing the "." that would make it work. Period(z).Return{s,j}
eval simply evaluates the string you pass to it, as if it was entered at command line, in the current workspace.
  1 commentaire
Iain
Iain le 7 Juin 2013
In light of your comment:
for z=1:periods
eval(['Period' num2str(z) 'Return{s,j}= open - close;'])
eval(['FReturnLMS{s,k} = Period' num2str(z) 'Return{s,j};'])
end
I would suggest that you consider just making it a 3D cell array {s,j,z}, or a cell array containing cell arrays {z}{s,j}

Connectez-vous pour commenter.

Plus de réponses (1)

ARS
ARS le 7 Juin 2013
Hi,
No, I wish to retain it as a cell array and thats why it ends with {}. I want the cell array name to be from Period1Return to Period28Return using loop and values assigned using
  • Period(z)Return{s,j}= open - close*
Thanks.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by