필터 지우기
필터 지우기

intquad function woes....

조회 수: 2 (최근 30일)
reuven zac
reuven zac 2017년 5월 7일
편집: Walter Roberson 2018년 4월 25일
I wrote this (homework) function that creates a large matrix from the sub-matrices (0), (1), (2) and (3) so that it will be in this form: (0) has all its element "0" etc.
(0) (1)
(3) (2)
=========
function [M] = intquad(m,n)
a = zeros(m,n);
b = ones(m,n);
c = b*2;
d = b*3;
M = [a b ; d c];
I went through each line in the command window and it worked flawlessly. I RAN x=intquad(m,n) with many combinations of (m,n) and got the expected outputs.
BUT, when I tested this function via HW4.p (yes, the Coursera brand) it tells me the function is incorrect and that
"Feedback: Your function made an error for argument(s) 2, 3 "
My questions are:
1. If the function is flawed, where lies the culprit?
2. What is meant by "argument(s) 2, 3" ?
Thanks
My apologies, it is my 1st/ posting here, and the Preview window does not make much sense.
  댓글 수: 3
reuven zac
reuven zac 2017년 5월 7일
편집: Walter Roberson 2017년 5월 8일
Here it is:
Write a function called intquad that takes as its input arguments two scalar positive integers named n and m in that order. The function returns Q, a 2n-by-2m matrix. Q consists of four n-by-m submatrices. The elements of the submatrix in the top left corner are all 0s, the elements of the submatrix at the top right are 1s, the elements in the bottom left are 2s, and the elements in the bottom right are 3s.
Prashanth Reddy Penta Reddy
Prashanth Reddy Penta Reddy 2017년 5월 20일
편집: Walter Roberson 2018년 4월 25일
function M = intquad1(m,n)
a = zeros(m,n);
b = ones(m,n);
c = b*2;
d = b*3;
M = [a b ; c d];
You did it right. Just interchange c and d in the final step.

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

채택된 답변

Steven Lord
Steven Lord 2017년 5월 8일
"the elements in the bottom left are 2s, and the elements in the bottom right are 3s."
You have these two blocks switched from the instructions in your assignment. Your code puts the block of 3's in the bottom left and the block of 2's in the bottom right.
  댓글 수: 1
reuven zac
reuven zac 2017년 5월 8일
Many thanks, Steven. I guess reading few times the problem statement is the key for good grades given by an automatos...

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

추가 답변 (1개)

Liban Abu
Liban Abu 2018년 4월 23일
편집: Walter Roberson 2018년 4월 25일
I started of with something like this
%Q(1:2:n, end:end:m)=1
%Q(end:end:n, end:end:m) =3
stuck on how to get the 2's on bottom Left

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by