Subscript indices must either be real positive integers or logicals.
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
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?
Réponses (1)
Star Strider
le 7 Mai 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.
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!