필터 지우기
필터 지우기

Matrix Dimensions do not agree?

조회 수: 1 (최근 30일)
Michael Jacobson
Michael Jacobson 2018년 5월 9일
편집: Stephen23 2018년 5월 10일
Trying to figure out why this for loop isn't working. Both fz and lsFX are 1x7 arrays, so I don't get why I'm getting the error matrix dimensions must agree
lsFX = zeros(1,7);
fz = 0.2e+03:0.2e+03:1.4e+03;
sr = -0.26:0.001:0.26;
for i=1:7
lsFX(1,i) = fz.*D.*sin(C.*atan((B.*(sr+.045)-E.*(B.*(sr+.045)...
-atan(B.*(sr+.045))))))-400;
end

채택된 답변

Geoff Hayes
Geoff Hayes 2018년 5월 9일
Michael - but sr is
sr = -0.26:0.001:0.26;
which is 1x521 which is the size of
sin(C.*atan((B.*(sr+.045)-E.*(B.*(sr+.045)...
-atan(B.*(sr+.045))))))-400
So when you are then multiplying that result by fz which is the 1x7...and so the error message makes sense.
  댓글 수: 3
Geoff Hayes
Geoff Hayes 2018년 5월 10일
Michael - so you want to multiply each of the seven values in fz against all of the elements in sr? Could you not transpose fz to get a 7x1 matrix and then multiply that by the sr, the 1x521, to get a 7x521 result?
Michael Jacobson
Michael Jacobson 2018년 5월 10일
Yes! I had actually realized this earlier before I saw your post Geoff. I guess I was stuck thinking one dimensionally, but thankfully I was looking at some homework that refreshed my memory on matrix operations.
I also got rid of the loop and my plot is exactly as I want it now. Thank you for your answers sir !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by