Matrix Dimensions Must Agree

조회 수: 2 (최근 30일)
Patrick voorhoeve
Patrick voorhoeve 2019년 3월 4일
댓글: Patrick voorhoeve 2019년 3월 4일
Okay so I'm very new to matlab, im just trying to create a simple user input unit converter to convert between farenheit, degrees and some metric units. For some reason however I keep getting the error "Matrix dimensions must agree" but only when I add the last elseif statement into the code.
function y = UnitConverter(from, to, inp)
if from == 'deg'
if to == 'far'
y = (inp * 9/5) + 32;
else
y = 'You cannot convert between these units';
end
elseif from == 'far'
if to == 'deg'
y = (32 - inp) * -5/9;
else
y = 'You cannot convert between these units';
end
elseif from == 'm'
if to == 'cm'
y = inp * 100;
elseif to == 'mm'
y = inp * 1000;
end
elseif from == 'cm'
if to == 'mm'
y = inp * 10;
elseif to == 'm'
y = inp / 100;
end
end
end
---------------------------------------------------------
Matrix dimensions must agree.
Error in UnitConverter (line 3)
if from == 'deg'

답변 (1개)

madhan ravi
madhan ravi 2019년 3월 4일
use strcmp() to compare strings
  댓글 수: 1
Patrick voorhoeve
Patrick voorhoeve 2019년 3월 4일
That worked, thank you!!! <3

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

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by