HOW TO SOLVE THIS?
1 次查看(过去 30 天)
显示 更早的评论

8 个评论
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
2023-1-1
Try this:
v = velocity([0, 5.6, 7], [0, 1.1, 2.4], [0, 4, 20], [0, 1, 2])
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 个评论
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 Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

