CORRECTION: The equation is supposed to be I(i) = (M * d(i)) ./ (2 * E * I); I was playing around with it and forgot to switch it back before I posted. The errors are still the same regardless
Error: Unable to perform assignment because the left and right sides have a different number of elements.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
At first I kept getting the error that the martix dimensions did not agree so I added the period before the operator "./" and now I am getting the error "Unable to perform assignment because the left and right sides have a different number of elements." I have attached my code below, the goal is to calculate strain with a changing diameter at an increment of 0.01.
F = 130;
Lb = 1.5;
T = (F * Lb) * 12;
M = T;
E = (9.863 * (10^6));
maxstrain = (1000 * (10^-6));
% Pipe Size 3
od3 = 3.5;
t3 = 0.216;
id3 = od3 - (2 * t3);
I3 = (pi / 4) * ((od3/2)^4) - ((id3)/2^4);
strain3 = (M * od3) / (2 * E * I3);
fprintf('The outer diamter for pipe size 3 is %.3f\n', od3)
fprintf('The strain for pipe size 3 is %.5f\n', strain3)
% Pipe Size 4
od4 = 4.5;
t4 = 0.237;
id4 = od4 - (2 * t4);
I4 = (pi / 4) * ((od4/2)^4) - ((id4)/2^4);
strain4 = (M * od4) / (2 * E * I4);
fprintf('The outer diamter for pipe size 4 is %.3f\n', od4)
fprintf('The strain for pipe size 4 is %.5f\n', strain4)
% Pipe Size 6
od6 = 6.625;
t6 = 0.280;
id6 = od3 - (2 * t6);
I6 = (pi / 4) * ((od6/2)^4) - ((id6)/2^4);
strain6 = (M * od6) / (2 * E * I6);
fprintf('The outer diamter for pipe size 6 is %.3f\n', od6)
fprintf('The strain for pipe size 6 is %.5f\n', strain6)
x = [od3, od4, od6];
y = [strain3, strain4, strain6];
subplot(2, 1, 1)
plot(x, y)
title('Outer Diamter vs Microstrain of Schedule 40 Pipe Sizes')
xlabel('Outer Diamter in inches')
ylabel('Microstrain')
inc = -0.01;
imax = 43;
din = od3;
d = zeros(43);
d = d(1:43);
I = zeros(43);
I = I(1:43);
for i = 1 : imax
d(i) = din - ((i-1).*inc);
I(i) = (M * dact) ./ (2 * E * I);
i = i + 1;
end
dact = d(:,1);
subplot(2, 1, 2)
plot(d, I)
2 Kommentare
Superficial
am 7 Jul. 2021
The reason you're getting that error is because Matlab is trying to fit 43 numbers (the result of the equation) into a space for a single number I(i).
Without knowing exactly what you're trying to achieve with the equation it's hard to know how to fix it. Perhaps you meant:
I(i) = (M * d(i)) ./ (2 * E * i); % (small i rather than I)
Your code is also kind of messy. I assume you've copied and pasted / adapted it rather than write it yourself? E.g:
d = zeros(43);
d = d(1:43);
For efficiency, should be replaced by:
d = zeros(1:43);
Also, you don't need the line
i = i+1
since your for loop will iterate that.
Antworten (1)
Arthi Sathyamurthi
am 20 Jul. 2021
Hello Alexis,
The error has occurred because both sides of the equation doesn’t have equal number of elements. Hence, try replacing the lines from 48-57 with the following code
d = zeros(1,43);
I = zeros(1,43);
for i = 1 : imax
d(i) = din - ((i-1).*inc);
I(i) = (M * d(i)) ./ (2 * E * i);
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!