Column vector calling in a loop

1 view (last 30 days)
I have been receiving 12 columns instead of 4 when I run it. I have tried to run a while loop to only run one value from the column at a time but I have been getting errors. I am not sure how to call specific row and column placements from the vectors. This is my crude attempt at it. I really appreciate your help. Any revamp is also appreciated.
R1=119.2; %%Resisters
R4=119.1; %%Resisters
Rpot=120.1; %%Potentiometer
Ro=120.2; %%Strain Gage Resistance Unloaded
Ri=909.0909;
Rf=1000000;
Vs=5; %%Voltage
GF=2.14; %%Gage Factor
E=10.4; %%Modulus of Elasticity Aluminium
Vo1=[0; 1.64; 1.565; 1.606; 1.615; 1.593; 1.648; 1.465; 1.595; 1.545; 1.63; 0;] %%Output voltage Item 1
Vo2=[0; 1.716; 1.56; 1.61; 1.661; 1.682; 1.705; 1.59; 1.64; 1.687; 1.661; 0;] %%Output voltage Item 2
Vo3=[1.667; 1.69; 1.68; 1.705; 1.711; 0; 1.698; 1.62; 1.626; 1.65; 1.687; 0;] %%Output voltage Item 3
Vo4=[1.75; 1.713; 1.635; 1.715; 1.766; 0; 0; 0; 0; 0; 0; 0;] %%Output voltage Item 4
Vbridge=[Vo1 Vo2 Vo3 Vo4]/((1+Rf/Ri)) %%Bridge Voltage Output
y=1
x=1
while x<=12
while y<=12
Rg(x,y)=-((Rpot*(Vbridge(x,y)+Vs)+R1*Vbridge(x,y))/(R4*Vbridge(x,y)+R1*(Vbridge(x,y)-Vs)))
y=y+1
end
x=1
x=x+1
end

Accepted Answer

Walter Roberson
Walter Roberson on 5 Nov 2015
Recode
y=1
x=1
while x<=12
while y<=12
Rg(x,y)=-((Rpot*(Vbridge(x,y)+Vs)+R1*Vbridge(x,y))/(R4*Vbridge(x,y)+R1*(Vbridge(x,y)-Vs)))
y=y+1
end
x=1
x=x+1
end
as a pair of for loops:
for x = 1 : 12
for y = 1 : 12
Rg(x,y)=-((Rpot*(Vbridge(x,y)+Vs)+R1*Vbridge(x,y))/(R4*Vbridge(x,y)+R1*(Vbridge(x,y)-Vs)))
end
end
  4 Comments
Chaz
Chaz on 5 Nov 2015
Do you know how to just make it print the last set of data found? It is printing every iteration right now. I know I didn't say I wanted that so your code is correct.
Walter Roberson
Walter Roberson on 5 Nov 2015
At the end of the Rg(x,y)= line, put a semi-colon
Rg(x,y)=-((Rpot*(Vbridge(x,y)+Vs)+R1*Vbridge(x,y))/(R4*Vbridge(x,y)+R1*(Vbridge(x,y)-Vs)));

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!