That is not a syntax error. You have not assigned a value to "i", so it has it's default value, and the default value for "i" (and for "j" as well) is sqrt(-1)
Help a noob with syntax!
3 次查看(过去 30 天)
显示 更早的评论
Okay I'm really new to Matlab and trying to code something for my assignment. Can someone please look at this code and tell me what all is wrong? I'm damn sure there is some syntax problem! The error I'm getting right now is:
Subscript indices must either be real
positive integers or logicals.
Error in RectangularSection (line 5)
D(i) = DeltaY*x;
CODE:
function [N]=RectangularSection(BaseWidth,Depth,RoughnessBase,RoughnessLeftFace,RoughnessRightFace,NoOfSections)
if NoOfSections > 0
DeltaY = Depth/NoOfSections;
for x=0:NoOfSections
D(i) = DeltaY*x;
N(i) = ((BaseWidth*RoughnessBase^(3/2)+DeltaY*x*RoughnessLeftFace^(3/2)+DeltaY*x*RoughnessRightFace^(3/2))/(BaseWidth + 2*x*DeltaY))^(2/3);
end
plot(N,D)
title('Roughness vs Depth');
xlabel('Depth');
ylabel('Roughness');
end
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!