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 个评论
Walter Roberson
2017-2-5
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
2017-2-5
That's the best "golf" score I can get, too, Walter...
John D'Errico
2017-2-5
编辑:John D'Errico
2017-2-5
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
2017-2-6
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
2017-2-6
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
2017-2-6
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
2017-2-6
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.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Numbers and Precision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!