Subscript indices must either be real positive integers or logicals.
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hi all.
I tried to run a Matlab script where I have to plot a certain graph, but I keep getting the same error message, Subscript indices must either be real positive integers or logicals.. My code is below:
syms s
De = 56;%mm, Do is also De
Di = 28.5; %mm
t = 2;
h = 1.6;
FN = 4440;
E =210e3;
nu = 0.3;
delta = De/Di
Cm = 4*E/(1-nu^2);
C4 = 1
C1 = (1/pi)*(((delta-1)/delta)^2/(((delta+1)/(delta-1))-(2/log(delta))))
F = Cm*t*s/(C1*De^2)*C4^2*(C4^2*(h-s)*(h-0.5*s)+t^2)
s1 = linspace(0,1.2,50); %1.2 because 0.75h, 0.75*1.6
plot(s1,F(s1),'-k','LineWidth',2), grid on, xlabel('s [mm]'), ylabel('F [N]')
set(gca,'FontSize',18)
Could anyone explain what the error means and where I should correct it?
Answers (1)
Star Strider
on 7 May 2019
In this instance (using the Symbolic Math Toolbox), it will work as you want if you create ‘F’ as a function:
F(s) = Cm*t*s/(C1*De^2)*C4^2*(C4^2*(h-s)*(h-0.5*s)+t^2)
If you were not using the Symbolic Math Toolbox, you would create ‘F(s)’ as an anonymous function:
F = @(s) Cm*t*s./(C1*De^2)*C4^2.*(C4^2*(h-s).*(h-0.5*s)+t^2);
Note the need to vectorise the multiplication and division operations using element-wise operations. See the documentation on Vectorization (link) for details.
You would call them the same way in your plot call.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!