Effacer les filtres
Effacer les filtres

Calling Konstants from string with name instead of index

1 vue (au cours des 30 derniers jours)
Jan w
Jan w le 30 Août 2017
Commenté : Jan w le 31 Août 2017
Hello everyone,
I have a string A containing konstants, which are calculated before.
A=[M_sig epsopen Emod sigopen]
Is there any way I can use the konstants name in equations instead of using the index? It would be great so I can recognice the used formula and don't need to check for the konstant name.
Like using
Emod*sigopen instead of A(3)*(4)
Thanks for your help

Réponse acceptée

Image Analyst
Image Analyst le 30 Août 2017
Yes, if you make A a table or structure. Here's a structure example:
% Create sample data.
M_sig =1;
epsopen = 2;
Emod = 3;
sigopen = 4;
% Create a structure.
A= struct('M_sig', M_sig, 'epsopen', epsopen, 'Emod', Emod, 'sigopen', sigopen)
% Do the math.
output = A.Emod * A.sigopen

Plus de réponses (1)

James Tursa
James Tursa le 30 Août 2017
Modifié(e) : James Tursa le 30 Août 2017
Are you just trying to do this?
[M_sig,epsopen,Emod,sigopen] = deal(A(1),A(2),A(3),A(4));

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by