Error using .* Array sizes must match.
45 views (last 30 days)
Show older comments
I need help with understanding the error in the summary of this prompt. Any help in troubleshooting would be greatly appreciated. Keep in mind this is only one section of the total code I am running, the parts before are where the functions are defined, which work with no problems
The code I am using is as follows:
syms x y
xv = linspace(0,35,350);
Snorm = (Mnet(xv) .* y_max) ./ I(xv);
Sshear = (Dnet(xv) .* Q(xv)) ./ (I(xv) .* t);
y6 = Snorm(xv);
y7 = Sshear(xv);
figure;
plot(xv, y6, 'blue');
title('Shear Stress');
xlabel('Position along the wing (m)');
ylabel('Stress (Pa)');
grid on;
figure;
plot(xv, y7, 'blue');
title('Normal Stress');
xlabel('Position along the wing (m)');
ylabel('Stress (Pa)');
grid on;
3 Comments
Stephen23
on 21 Nov 2024 at 12:45
The sizes of the arrays you are attempting to multiply are not compatible:
Allow debugging on error by calling
dbstop if error
and then check the sizes of all of the arrays used in that operation.
Answers (2)
Animesh
on 21 Nov 2024 at 12:46
Hey @Joaquin
The error you're encountering is due to the sizes of "Mnet(xv)" and "y_max," "Dnet(xv)" and "Q(xv)," or "I(xv)" and "t" not being compatible.
For element-wise multiplication, the sizes of both arrays must be either the same or compatible.
You can refer to the following MathWorks documentation for more information on element-wise multiplication: https://www.mathworks.com/help/matlab/ref/double.times.html
0 Comments
Image Analyst
on 22 Nov 2024 at 1:26
Add these extra lines and tell us what you see in the command window:
whos mNet
whos y_max
whos I
whos Dnet
whos Q
whos t
Snorm = (Mnet(xv) .* y_max) ./ I(xv);
Sshear = (Dnet(xv) .* Q(xv)) ./ (I(xv) .* t);
Since you're using element-by-element multiplication the sizes of all of those must match. However y_max and y could also be a single scalar number and it would work. The others should be vectors or functions. If they are vectors, then
xv = linspace(0,35,350)
etc.
will give you problems because xv has a zero and a bunch of fractional numbers in it and arrays and vectors can take only integers as indexes, not zeros and fractions as you currently have xv.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!