HOW TO SOLVE THIS?

조회 수: 5 (최근 30일)
daniel
daniel 2023년 1월 1일
댓글: Voss 2023년 1월 3일
  댓글 수: 8
daniel
daniel 2023년 1월 1일
Walter Roberson
Walter Roberson 2023년 1월 1일
In the case of that error message, the problem is that you had accidentally created a variable named velocity that you are then trying to index. If there is a variable in scope and a function of the same name, MATLAB gives priority to the variable in scope.

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

채택된 답변

Image Analyst
Image Analyst 2023년 1월 1일
Try this:
v = velocity([0, 5.6, 7], [0, 1.1, 2.4], [0, 4, 20], [0, 1, 2])
v = 1×2
6.9692 16.1137
function v = velocity(x,y,z,t)
v = [];
if ~isequal(size(x), size(y)) || ~isequal(size(x), size(z)) || ~isequal(size(x), size(t))
uiwait(errordlg('Sizes do not match'));
return;
end
v = sqrt(diff(x).^2+diff(y).^2+diff(z).^2)./diff(t);
end
  댓글 수: 5
daniel
daniel 2023년 1월 1일
its working tnks
Voss
Voss 2023년 1월 3일
@daniel: isequal accepts more than two input arguments and returns true if and only if all the inputs are equivalent.
That is, you can replace this:
if ~isequal(size(x), size(y)) || ~isequal(size(x), size(z)) || ~isequal(size(x), size(t))
with this:
if ~isequal(size(x), size(y), size(z), size(t))

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by