Help Creating the following matrix

조회 수: 2 (최근 30일)
Carlos Martinez
Carlos Martinez 2020년 2월 19일
댓글: Carlos Martinez 2020년 2월 19일
Create a matrix using functions zeros(), ones() and/or eye()
3 0 2 2
0 3 2 2
0 0 3 0
  댓글 수: 1
Adam Danz
Adam Danz 2020년 2월 19일
What's your question? Where are you stuck in this task?
To learn about the functions you listed and to see examples, search for them in the documentation.

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2020년 2월 19일
편집: John D'Errico 2020년 2월 19일
Very easy, really.
A = zeros(3,4);
A(1,1) = 3*eye;
A(1,3) = 2*ones;
A(1,4) = 2*ones;
A(2,2) = 3*eye;
A(2,3) = 2*ones;
A(2,4) = 2*eye;
A(3,3) = 3*ones;
A =
3 0 2 2
0 3 2 2
0 0 3 0
Oh, darn. This is actually your homework, and I just did it for you. (Did you notice I use eye there sometimes, and ones other times, but for absolutely no good reason for that choice?)
Anyways ... maybe, just maybe, there is a shorter way to solve it.
I got it now! This should work, in only one line:
A = [3 0 2 2;0 3 2 2;0 0 3 0]*ones + zeros;
As you can see, it uses both ones and zeros. I could even have included a use of eye in there too.
A = eye(3)*[3 0 2 2;0 3 2 2;0 0 3 0]*ones + zeros;
  댓글 수: 1
Carlos Martinez
Carlos Martinez 2020년 2월 19일
Thank you so much I was stuck on this for a while

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by