Error using .* Array sizes must match.

조회 수: 8 (최근 30일)
Joaquin
Joaquin 2024년 11월 21일
답변: Image Analyst 2024년 11월 22일
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
Joaquin
Joaquin 2024년 11월 21일
This is all of the red text from the error that I get.
I have attached a screenshot of the message I see.
Stephen23
Stephen23 2024년 11월 21일
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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Animesh
Animesh 2024년 11월 21일
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

Image Analyst
Image Analyst 2024년 11월 22일
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)
xv = 1×350
0 0.1003 0.2006 0.3009 0.4011 0.5014 0.6017 0.7020 0.8023 0.9026 1.0029 1.1032 1.2034 1.3037 1.4040 1.5043 1.6046 1.7049 1.8052 1.9054 2.0057 2.1060 2.2063 2.3066 2.4069 2.5072 2.6074 2.7077 2.8080 2.9083
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by