Create the following matrix by typing one command..

I can't type individual elements explicitly, and I want to create the following matrix by typing only one command.
D =
1 1 1 1; 1 1 1 1; 1 1 1 1; 8 6 4 2;
Thank you so much!

7 commentaires

If "command" means the same as "function calls" then I think it needs at least 3, even if they all go into a single expression.
dpb
dpb le 5 Fév 2017
That's the best "golf" score I can get, too, Walter...
John D'Errico
John D'Errico le 5 Fév 2017
Modifié(e) : John D'Errico le 5 Fév 2017
I can think of more than one way to get a golf score of 3, but 2? That will be tough.
Jenn - the point is, there are multiple ways to do it. But you need to try. If we give you the answer, then you learn nothing, except that you can sometimes find someone gullible enough to do your job for you.
Note for anyone who might be wondering about our counts: In MATLAB, what are commonly talked about as operators are really function calls. Even assignment is a function call. And when we say "3", we are counting all of those.
May I ask why you want to do it in one command? Also, do you have any reason why you believe it is even possible?
Looks like homework to me. And having seen similar questions before, I suspect that a single expression with multiple (implicit) function calls would be fine. As compared to, for example, a solution that build part of it and then used assignment statements to finish the job.
As a followup to what Walter said about counting function calls, the operation [1 2 3] is a function call, because [] is equivalent to a call to cat. As well, I'd point out that [1:3] is TWO function calls, since the colon operator is a call to the colon function.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by