Creating a matrix with specific sequence

3 vues (au cours des 30 derniers jours)
Gina Barlage
Gina Barlage le 24 Mai 2015
Commenté : Gina Barlage le 25 Mai 2015
I was given this as a homework assignment but I am not really sure where to even start. Would this be a loop creation? Nested loop?
The script should assume values are specified on a command line before being run. The script should be able to take values of a, b, c, and n, and output a 3-x-n matrix B such that
B = [a a^2 ... a^n; b 2b ... nb; nc (n-1)c ... c]
Proper execution of the script would appear as follows:
>> a = 2; b = 3; c = 4; n = 3;
>> script18
B =
2 4 8
3 6 9
12 8 4
Note that this script should function for any integer values of a, b, c and n.
  2 commentaires
Stephen23
Stephen23 le 25 Mai 2015
Modifié(e) : Stephen23 le 25 Mai 2015
There is no need to use loops to solve everything in MATLAB. In fact there are much neater and faster ways of using MATLAB most effectively: by writing fully vectorized code instead, as Walter Roberson has hinted to you already.
Gina Barlage
Gina Barlage le 25 Mai 2015
How would I get it into a matrix form? Would I use a command like the zeros or ones? Thank you for the hint.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 24 Mai 2015
Hints:
7.^(1:10)
(10:-1:1)

Catégories

En savoir plus sur Loops and Conditional Statements 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