I need a Variable like x to have 3 different values and matlab to calculate the whole code based on those 3 values simultaneously. then I need another variable to have 3 different values, so I will have 9 different answers based on that change. but I need matlab to give me a matrix as (9,1)..any helps?

Réponses (1)

John D'Errico
John D'Errico le 7 Fév 2023
Modifié(e) : John D'Errico le 7 Fév 2023
[x,y] = meshgrid(1:3,[2 3 5])
x = 3×3
1 2 3 1 2 3 1 2 3
y = 3×3
2 2 2 3 3 3 5 5 5
z = x+y
z = 3×3
3 4 5 4 5 6 6 7 8
If you need it as a 9x1 array, then just unroll the arrays into vectors.
z = z(:)
z = 9×1
3 4 6 4 5 7 5 6 8
Start to learn how to use MATLAB as it is designed to be used, instead of writing everything as a loop.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by