How do I save the output array (y2) for each loop?
显示 更早的评论
How do I save the output array (y2) for each loop?
At the end, I would like a 3x10 array stored in the variable ysum. Where each row is the unique calculation based on the "c" count.
I've been going at this for 6 hours and can't seem to get it.
Thanks in advanced.
Fmultiple = input('Enter multiple concentrated forces [N] in array format: ');
amultiple = input(sprintf('Enter multiple locations (0 - %0.0f) [m]: ', L));
z = length(amultiple); % this is the length of the amultiple user vector input
% a new blank vector must be created to which outputs in the loops will be
% appended
ysum = [];% this will store all the values of the deflection calculations
c = 0;
for i = 1:z; % this loop from spot 1 of the array inputed all the way to the end
a = amultiple(i) % indexes i for amultiple array
F = Fmultiple(i) % indexes i for Fmultiple array
c = c + 1
y = [] % reset y each round
I = (w .* (h .^3)) ./ 12;
R = (F ./ L) .* (L - a);
theta = ((F .* a) ./ (6 .* E .* I .* L)) .* ((2 .* L) - a) .* (L - a);
if c > 0
y1 = [];
y2 = [];
x = 0:L;
for n = 1:length(x);
if x(n) <= a
def = (-1 .* theta .* x(n)) + ((R * x(n) .^3) ./ (6 .* E .* I));
y1 = [y1, def];
else
def = (-1 .* theta .* x(n)) + ((R * x(n) .^3) ./ (6 .* E .* I)) - ((F ./ (6 .* E .* I)) .* ((x(n) - a) .^3));
y2 = [y1, def];
ysum %<=== %MARKED
end
end
end
end
采纳的回答
更多回答(1 个)
Walter Roberson
2021-10-17
Under what circumstance could c be <= 0 such that the if would fail ?
amultiple = input(sprintf('Enter multiple locations (0 - %0.0f) [m]: ', L));
That tells us that L is a length in meters.
x = 0:L;
That tells us that L is an integer count, not a fractional length.
for n = 1:length(x);
The way you constructed x, x is always going to be integers, and n is always going to be x+1
if x(n) <= a
Why bother with x there when you could just use n? If n<=a+1 ?
ysum %<=== %MARKED
could you confirm that should only be assigned into if the if fails?
I would like a 3x10 array stored in the variable ysum
Where does the 3 come from? Where does the 10 come from?
Your a values are obviously expected to be different. Why would you expect the same number of columns of output for the different a values ?
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!