Help a noob with syntax!
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 14 Apr 2013
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)
0 Comments
See Also
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!