Create the following matrix by typing one command..
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 5 Feb. 2017
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
am 5 Feb. 2017
That's the best "golf" score I can get, too, Walter...
John D'Errico
am 5 Feb. 2017
Bearbeitet: John D'Errico
am 5 Feb. 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.
Walter Roberson
am 6 Feb. 2017
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.
the cyclist
am 6 Feb. 2017
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?
Walter Roberson
am 6 Feb. 2017
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.
John D'Errico
am 6 Feb. 2017
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.
Antworten (0)
Kategorien
Mehr zu Numbers and Precision finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!