Filter löschen
Filter löschen

Subtracting the previous number in a for loop

9 Ansichten (letzte 30 Tage)
Cory Powell
Cory Powell am 3 Mai 2016
Kommentiert: Cory Powell am 3 Mai 2016
Hello,
I can't seem to figure this one out and would appreciate some guidance.
I am attempting to create a for loop, as entering it manually for each point would be a pain in the rear, that would subtract values from itself.
i.e. say I have 100, I would like the for loop to subtract a found value from the previous value within the loop.
Here's the code.
close all
clear all
clc
%%Problem 1
%Beam Data
Avfy3 = 8.8; %kips No. 3 Grade 40 double-leg
Av3 = Avfy3/(40); %in2 for two
Asfy4 = 190; %kips No. 4 Grade 60
As = Asfy4/(4*60); %in2 for single bar
As4 = Asfy4/(60); %in2 for all bars
bw = 12; %in beam width
jd = 20; %in Comp to Long steel spacing
S1 = 6; %in, Spacing of No. 3 Bars
S1n = 8; %number of spaces
S2 = 12; %in, Spacing of No. 3 Bars
S2n = 4; %number of spaces
P1 = 26.4; %kips, End of L1 span
P2 = P1; %kips, End of L2 span
PM = 52.8; %kips, Middle of beam
%Begin Solution
disp('Part (a)')
Length = [12,24,36,36,30,24....
18,24,30,36,36,36,30,24,18,12,6];
LAv = Length*Avfy3;
Fjd = LAv/jd;
Label = {'U12-L11','U12-L10','U12-L9','U11-L8','U10-L7','U9-L6','U8-L5'...
'U8-L4','U8-L3','U8-L2','U7-L1','U6-L0','U5-L0','U4-LO'...
'U3-LO','U2-LO','U1-LO'};
for i = 1:17
MemberForce = [Label(:,i),Fjd(:,i)];
end
%Sum moment @ U12
M12 = PM*8-P1*4; %kip-ft
Mjd12 = (M12*12)/jd; %kips
M8 = PM*4; %kip-ft
Mjd8 = (M8*12)/jd; %kips
TF1 = Mjd12-Fjd(1,1)
for i = 2:17
TF = TF1 - Fjd(:,i)
end
The problem area is the only for loop present. I don't know how to have Fjd subtracted from the previous value found and keep doing it until all the integers have been used up. TF1 is the initial point of interest. It just takes a new value of Fjd and subtracts it from TF1 instead of using say TF(1)-Fjd.
Any help would be great.
Thank you,
Cory M Powell
  1 Kommentar
Cory Powell
Cory Powell am 3 Mai 2016
Sorry the for loop with TF within it. The last for loop

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 3 Mai 2016
for i = 2:17
TF1 = TF1 - Fjd(:,i)
end
  2 Kommentare
Cory Powell
Cory Powell am 3 Mai 2016
Part (a) Cannot find an exact (case-sensitive) match for 'TF'
The closest match is: tf in C:\Program Files\MATLAB\R2015b\toolbox\control\control\@tf\tf.m
Error in Homework_9 (line 50) TF = TF - Fjd(:,i)
>> Thanks for the rapid answer, do you have any thoughts on this error message?
Cory Powell
Cory Powell am 3 Mai 2016
Sorry you are right. I entered it incorrectly.
Thanks man, Cory

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming 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!

Translated by