Error using .* Array sizes must match.
46 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Stephen23
il 21 Nov 2024 alle 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.
Risposte (2)
Animesh
il 21 Nov 2024 alle 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 Commenti
Image Analyst
il 22 Nov 2024 alle 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 Commenti
Vedere anche
Categorie
Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!