write a matrix from a function (say h(m,n), where m and n are running index)

1 vue (au cours des 30 derniers jours)
sachin k
sachin k le 30 Août 2017
Commenté : sachin k le 30 Août 2017
Suppose I want to write a matrix from a function (h(m,n)), so in mathematica, It can be written in foollowing way " Table[h[m, n], {m, 1, 3}, {n,1, 3}];" this will wrtie a matrix of 3x3, how to do the same thing in matlab ??

Réponses (1)

José-Luis
José-Luis le 30 Août 2017
Modifié(e) : José-Luis le 30 Août 2017
myFun = @(x,y) x.^2 + y;
result = bsxfun(myFun,1:3,(1:3).')
If I understood your question right, then you'd just need to replace myFun with your own function.
  4 commentaires
José-Luis
José-Luis le 30 Août 2017
el should produce a scalar for this approach to work. I don't have the symbolic math toolbox so I can't test your code.
sachin k
sachin k le 30 Août 2017

@jose, It's ok!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by