필터 지우기
필터 지우기

what am I doing wrong here?

조회 수: 1 (최근 30일)
Jonathan Trencheny
Jonathan Trencheny 2016년 2월 15일
답변: Star Strider 2016년 2월 15일
function a = problem4c (m)
m=4;
a = [1:m; 2:m; 3:m; 4:m; 5:m];
x = mean(a);
avg = mean(x);
I keep getting, in red letters:
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in problem4c (line 3)
a = [1:m; 2:m; 3:m; 4:m; 5:m];
Error in run (line 96)
evalin('caller', [script ';']);

답변 (2개)

Image Analyst
Image Analyst 2016년 2월 15일
The rows don't have all the same number of columns. Instead of putting the vectors into different rows with semicolons, put them into the same row with commas:
a = [1:m, 2:m, 3:m, 4:m, 5:m];
  댓글 수: 2
Jonathan Trencheny
Jonathan Trencheny 2016년 2월 15일
I see, and that makes sense, however what would we do if we need to keep it a matrix?
Walter Roberson
Walter Roberson 2016년 2월 15일
a = {1:m; 2:m; 3:m; 4:m; 5:m};
x = cellfun(@mean, a);

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


Star Strider
Star Strider 2016년 2월 15일
I don’t know what the problem statement is, but from what I’ve seen, one option might be:
m = 4;
v = m:-1:0;
c = cumsum(0:m);
s = sum(1:m) - c;
avg = s./v
avg =
2.5 3 3.5 4 NaN

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by