Check every if or elseif statements during a for loop - matlab

I am really new to MATLAB and I am trying to write this code. But I am not sure if the if or elseif statement is working properly. I also know maybe a lot of problem is in my code now, which if someone notice it would vary appreciate to mention it. But my question is how can i check if really every statement is checked with MATLAB during this for loop.
Sincerely sorry for the lot of code.
Ps. I don know why I'm getting 0 at the beginning of every array like delta_theta.
clc
B=1.2;H=0.35;R=2.93;b=1;h=0.24;d_c=0.06;e_s=0.055;D_s=0.03;d_s=0.4;r_s=15*10^(-3);N_s=2;E_s=200*10^(9);f_y=500*10^(6);E_c=43.6*10^(9);v_c=0.24;f_c=35.5*10^(6);F=1.9;
A_s=pi*r_s^2;
M=zeros(200,200);
N=zeros(200,200);
delta_thetavalue=zeros(200,1);
delta_lvalue=zeros(1,200);
Idx_1 = 1;
for delta_theta =-10:0.1:10
Idx_1 = Idx_1 + 1;
Idx_2 = 1;
alpha_e=0;
alpha_p=0;
beta_e=0;
beta_p=0;
r_b=0;
r_s=0;
r_e=0;
delta_thetavalue(Idx_1)=delta_theta;
A=r_s-(f_y*d_s/(E_s*delta_theta));
for delta_l=-10:0.1:10
Idx_2 = Idx_2 + 1;
delta_lvalue(Idx_2)=delta_l;
r_0=R-(delta_l/delta_theta);
r_1=1/delta_theta*(delta_l+(F*f_c*d_c)/E_c);
if delta_theta >= 0
r_op=R+h/2;
r_cl=R-h/2;
if r_0 >= r_op && r_1<=r_cl
alpha_e=1;
r_b=r_op;
r_e=r_cl;
elseif r_0 >=r_op && r_cl<r_1 && r_1<r_op
alpha_e=1;
alpha_p=1;
r_b=r_op;
r_e=r_1;
elseif r_0 >=r_op && r_1>=r_op
alpha_p=1;
r_b=r_op;
r_e=r_op;
elseif r_s<r_0 && r_0<r_op && r_1<=r_cl
alpha_e=1;
r_b=r_0;
r_e=r_cl;
elseif r_s<r_0 && r_0<r_op && r_1>r_cl
alpha_e=1;
alpha_p=1;
r_b=r_0;
r_e=r_cl;
elseif A<r_0 && r_cl<r_0 && r_0<=r_s && r_1<=r_cl
alpha_e=1;
beta_e=1;
r_b=r_0;
r_e=r_cl;
elseif A<r_0 && r_cl<r_0 && r_0<=r_s && r_1>r_cl
alpha_e=1;
alpha_p=1;
beta_e=1;
r_b=r_0;
r_e=r_1;
elseif A>=r_0 && r_0>r_cl && r_1<=r_cl
alpha_e=1;
beta_p=1;
r_b=r_0;
r_e=r_cl;
elseif A>=r_0 && r_0>r_cl && r_1>r_cl
alpha_e=1;
alpha_p=1;
beta_p=1;
r_b=r_0;
r_e=r_1;
elseif r_0 <= r_cl
r_b=r_cl;
r_e=r_cl;
end
elseif delta_theta < 0
r_op=R-h/2;
r_cl=R+h/2;
if r_0 <= r_op && r_1 >= r_cl
alpha_e=1;
r_b=r_op;
r_e=r_cl;
elseif r_0 <=r_op && r_cl>r_1 && r_1>r_op
alpha_e=1;
alpha_p=1;
r_b=r_op;
r_e=r_1;
elseif r_0 <=r_op && r_1>r_op
alpha_p=1;
r_b=r_op;
r_e=r_op;
elseif r_s>r_0 && r_0>r_op && r_1>=r_cl
alpha_e=1;
r_b=r_0;
r_e=r_cl;
elseif r_s>r_0 && r_0>r_op && r_1<r_cl
alpha_e=1;
alpha_p=1;
r_b=r_0;
r_e=r_cl;
elseif A>r_0 && r_cl>r_0 && r_0>=r_s && r_1>=r_cl
alpha_e=1;
beta_e=1;
r_b=r_0;
r_e=r_cl;
elseif A>r_0 && r_cl>r_0 && r_0>=r_s &&r_1<r_cl
alpha_e=1;
alpha_p=1;
beta_e=1;
r_b=r_0;
r_e=r_1;
elseif A<=r_0 && r_0>r_cl && r_1>=r_cl
alpha_e=1;
beta_p=1;
r_b=r_0;
r_e=r_cl;
elseif A<=r_0 && r_0<r_cl &&r_1<r_cl
alpha_e=1;
alpha_p=1;
beta_p=1;
r_b=r_0;
r_e=r_1;
elseif r_0 >= r_cl
r_b=r_cl;
r_e=r_cl;
end
end
M(Idx_1,1)=alpha_e*(E_c*b)/d_c*((delta_l/2)*abs((r_b-R)^2-(r_e-R)^2)+delta_theta*abs((r_b-R)^3-(r_e-R)^3))+alpha_p*(-F*f_c*b*abs(r_cl-r_e)*((r_cl+r_e)/2-R))+beta_e*E_s*A_s*(delta_l/d_s+delta_theta/d_s*(r_s-R))*(r_s-R)+beta_p*f_y*A_s*(r_s-R);
N(Idx_1,1)=alpha_e*(E_c*b)/d_c*(delta_l*(r_e-r_b)*(delta_theta/2)*abs((r_s-R)^2-(r_b-R)^2))+alpha_p*(-F*f_c*b*abs(r_cl-r_e))+beta_e*E_s*A_s*(delta_l/d_s+delta_theta/d_s*(r_s-R))+beta_p*f_y*A_s;
end
end
j=M/(E_c*b*h^2);
figure(1)
plot(delta_thetavalue, j)```

This is more of a comment than a real answer (since I have not understood the question): it is difficult to follow all possible branching because a lot of conditions are redundant. To solve this, it may be a good idea to do some nesting, e.g. this:
if cond1 && cond2 && cond3
statement1
elseif cond1 && cond2 && ~cond3
statement2
end
should become this:
if cond1 && cond2
if cond3
statement1
else
statement2
end
end
so that it is now clearer that e.g. ~cond1 is not covered while cond3 is in either cases.

Related

An array for multiple LHS assignment cannot contain LEX_TS_STRING error

New to programing in matlab. I am currently trying to make a MATLAB program that will find the critical values of a multi-variable function and tell me whether each are a minimum, maximum, or saddle point. Unfortunately I always get the error : An array for multiple LHS assignment cannot contain LEX_TS_STRING
Any help will be very appreciated.
here's the code:
function [c,d] = critcalpoints(f)
syms x y
f(x,y)=x^3-3*x^2+5*x*y-7*y^2;
gradf = jacobian(f(x,y));
hessmatf = jacobian(gradf,[x,y]);
[xcr,ycr]=solve(gradf(1),gradf(2));
H1=subs(hessmatf,[x,y],[xcr(1),ycr(1)]);
H2=subs(hessmatf,[x,y],[xcr(2),ycr(2)]);
eig(H1);
eig(H2);
c = double(eig(H1));
d = double(eig(H2));
if (c(1) > 0 && d(1) > 0) || (c(2) > 0 && d(2) > 0)
print([xcr,ycr],' is a minimum')
elseif (c(1) < 0 && d(1) < 0) || (c(2) < 0 && d(2) < 0)
print( [xcr, ycr], ' is a maximum')
elseif (c(1) < 0 && d(1) > 0) || (c(1) > 0 && d(1) < 0)
print( [xcr, ycr], ' is a saddle point')
elseif (c(2) < 0 && d(2) > 0) || (c(2) > 0 && d(2) < 0)
print( [xcr, ycr], ' is a saddle point')
elseif (c(1)==0 || d(1)==0)
print( [xcr, ycr], ' is degenerate')
elseif (c(2)==0 || d(2)==0)
print( [xcr, ycr], ' is degenerate')
end
Cannot reproduce your error. The code can work but you need to change print to something else as print doesn't do what you think it does. The print function prints a figure that is open to file. Change it so that you display xcr and ycr first then display the right condition to satisfy after. Use disp instead:
syms x y
f(x,y)=x^3-3*x^2+5*x*y-7*y^2;
gradf = jacobian(f(x,y));
hessmatf = jacobian(gradf,[x,y]);
[xcr,ycr]=solve(gradf(1),gradf(2));
H1=subs(hessmatf,[x,y],[xcr(1),ycr(1)]);
H2=subs(hessmatf,[x,y],[xcr(2),ycr(2)]);
eig(H1);
eig(H2);
c = double(eig(H1));
d = double(eig(H2));
disp([xcr, ycr]); % Display the solutions first
if (c(1) > 0 && d(1) > 0) || (c(2) > 0 && d(2) > 0)
disp('is a minimum')
elseif (c(1) < 0 && d(1) < 0) || (c(2) < 0 && d(2) < 0)
disp('is a maximum')
elseif (c(1) < 0 && d(1) > 0) || (c(1) > 0 && d(1) < 0)
disp('is a saddle point')
elseif (c(2) < 0 && d(2) > 0) || (c(2) > 0 && d(2) < 0)
disp('is a saddle point')
elseif (c(1)==0 || d(1)==0)
disp('is degenerate')
elseif (c(2)==0 || d(2)==0)
disp('is degenerate')
end
I get:
[ 0, 0]
[ 59/42, 295/588]
is a maximum

How to include piecewise defined functions in bvp4c solver in Matlab

I am having trouble using the bvp4c with piecewise defined functions.
I tested the code and it works fine when the piecewise defined functions are constant.
The problem is that I get wrong results in the graph (that I know for sure) in the area where the piecewise defined functions are not constant.
Any ideas or suggestions on how to handle this problem?
Thanks
function bvp4
xlow=0;
xhigh=0.30;
solinit=bvpinit(linspace(xlow,xhigh,1000),[0 0]);
sol = bvp4c(#bvp4ode,#bvp4bc,solinit);
xint=[xlow:0.0001:xhigh];
Sxint=deval(sol,xint);
Sxint1=abs(sqrt(Sxint));
xint=[xlow:0.0001:xhigh];
plot(xint,Sxint1(1,:),'r')
function dydx = bvp4ode(x,y)
So=0.00125;
s=1.5;
dydx = [y(2);
((G(x)+125*f(x)*y(1)*(1+1/s^2)^0.5-1000*9.81*So*H(x))/(1000*0.5*l(x)*(f(x)/8)^0.5)-y(2)*2*(-2/3*x+0.071+2/3*0.08)*(-2/3)*b(x))/H(x)/H(x)];
function res = bvp4bc(ya,yb)
res = [ya(1); yb(1)];
function fval = f(x)
if (x >= 0) && (x <= 0.08)
fval = 0.0187;
elseif (x > 0.08) && (x <= 0.17)
fval = 0.0298;
elseif (x > 0.17) && (x <= 0.3)
fval= 0.0408;
end
function Gval = G(xint)
if (xint >= 0) && (xint <= 0.08)
Gval = 0.1306;
elseif (xint > 0.08) && (xint <= 0.17)
Gval = 0.1306;
elseif (xint > 0.17) && (xint <= 0.3)
Gval = -0.0337;
end
function Hval = H(xint)
if (xint >= 0) && (xint < 0.08)
Hval = 0.071;
elseif (xint >= 0.08) && (xint <= 0.17)
Hval = -2/3*xint+(0.071+2/3*0.08);
elseif (xint >0.17) && (xint <= 0.3)
Hval = 0.011;
end
function bval = b(xint)
if (xint >= 0) && (xint < 0.08)
bval = 0;
elseif (xint >= 0.08) && (xint <= 0.17)
bval = 1;
elseif (xint > 0.17) && (xint <= 0.3)
bval= 0;
end
function lval = l(xint)
if (xint >= 0) && (xint <= 0.08)
lval = 0.067;
elseif (xint > 0.08) && (xint <= 0.17)
lval = 0.134;
elseif (xint > 0.17) && (xint <= 0.3)
lval= 1.165;
end
Thou shalt not surprise your fragile solver with sudden jumps.
Any order p solver expects an ODE function that is at least p times continuously differentiable to sensibly adapt the mesh of gridpoints resp. the local step size. Any deviation leads to excessive and possibly oscillating adaptation near the singular points, resulting in long computation times or underflow in the step size.
I see two possibilities to work around this problem, use events (if supported for BVP) to switch models/ODE functions or use the provided multipoint mechanism to split the integration interval into sections where your parameter functions are constant. Then you can also use simple arrays for the parameters instead of functions with many branchings.

MATLAB: Fixing Logarithmic Axes

I am plotting a series of probability density functions (PDFs) with log scales for both axes. Problem is, they keep changing depending on which data I am analyzing. I'd like to fix the Y-axis from 10^-12 to 10^-28, and X-axis from 10^10 to 10^20. Any ideas?
Thanks!
clc;
clear all;
load Aug2005_basin_variables.mat
% Initialize
j_len = length(W_SH);
prob_dens_all = zeros(j_len,30);
ii = 1 : j_len;
count(1:30) = 0;
bin(1:30) = 0;
for i = 1 : 30
bin(i) = 10^(11 + (0.3*i));
end
% Bin the Watts
for i = 1 : j_len
if((log10(W_SH(i)) >= 11) && (log10(W_SH(i)) < 11.3))
count(1) = count(1) + 1;
end
if((log10(W_SH(i)) >= 11.3) && (log10(W_SH(i)) < 11.6))
count(2) = count(2) + 1;
end
if((log10(W_SH(i)) >= 11.6) && (log10(W_SH(i)) < 11.9))
count(3) = count(3) + 1;
end
if((log10(W_SH(i)) >= 11.9) && (log10(W_SH(i)) < 12.2))
count(4) = count(4) + 1;
end
if((log10(W_SH(i)) >= 12.2) && (log10(W_SH(i)) < 12.5))
count(5) = count(5) + 1;
end
if((log10(W_SH(i)) >= 12.5) && (log10(W_SH(i)) < 12.8))
count(6) = count(6) + 1;
end
if((log10(W_SH(i)) >= 12.8) && (log10(W_SH(i)) < 13.1))
count(7) = count(7) + 1;
end
if((log10(W_SH(i)) >= 13.1) && (log10(W_SH(i)) < 13.4))
count(8) = count(8) + 1;
end
if((log10(W_SH(i)) >= 13.4) && (log10(W_SH(i)) < 13.7))
count(9) = count(9) + 1;
end
if((log10(W_SH(i)) >= 13.7) && (log10(W_SH(i)) < 14.0))
count(10) = count(10) + 1;
end
if((log10(W_SH(i)) >= 14.0) && (log10(W_SH(i)) < 14.3))
count(11) = count(11) + 1;
end
if((log10(W_SH(i)) >= 14.3) && (log10(W_SH(i)) < 14.6))
count(12) = count(12) + 1;
end
if((log10(W_SH(i)) >= 14.6) && (log10(W_SH(i)) < 14.9))
count(13) = count(13) + 1;
end
if((log10(W_SH(i)) >= 14.9) && (log10(W_SH(i)) < 15.2))
count(14) = count(14) + 1;
end
if((log10(W_SH(i)) >= 15.2) && (log10(W_SH(i)) < 15.5))
count(15) = count(15) + 1;
end
if((log10(W_SH(i)) >= 15.5) && (log10(W_SH(i)) < 15.8))
count(16) = count(16) + 1;
end
if((log10(W_SH(i)) >= 15.8) && (log10(W_SH(i)) < 16.1))
count(17) = count(17) + 1;
end
if((log10(W_SH(i)) >= 16.1) && (log10(W_SH(i)) < 16.4))
count(18) = count(18) + 1;
end
if((log10(W_SH(i)) >= 16.4) && (log10(W_SH(i)) < 16.7))
count(19) = count(19) + 1;
end
if((log10(W_SH(i)) >= 16.7) && (log10(W_SH(i)) < 17.0))
count(20) = count(20) + 1;
end
if((log10(W_SH(i)) >= 17.3) && (log10(W_SH(i)) < 17.6))
count(21) = count(21) + 1;
end
if((log10(W_SH(i)) >= 17.6) && (log10(W_SH(i)) < 17.9))
count(22) = count(22) + 1;
end
if((log10(W_SH(i)) >= 17.9) && (log10(W_SH(i)) < 18.2))
count(23) = count(23) + 1;
end
if((log10(W_SH(i)) >= 18.2) && (log10(W_SH(i)) < 18.5))
count(24) = count(24) + 1;
end
if((log10(W_SH(i)) >= 18.5) && (log10(W_SH(i)) < 18.8))
count(25) = count(25) + 1;
end
if((log10(W_SH(i)) >= 18.8) && (log10(W_SH(i)) < 19.1))
count(26) = count(26) + 1;
end
if((log10(W_SH(i)) >= 19.1) && (log10(W_SH(i)) < 19.4))
count(27) = count(27) + 1;
end
if((log10(W_SH(i)) >= 19.4) && (log10(W_SH(i)) < 19.7))
count(28) = count(28) + 1;
end
if((log10(W_SH(i)) >= 19.7) && (log10(W_SH(i)) < 20.0))
count(29) = count(29) + 1;
end
if((log10(W_SH(i)) >= 20.0) && (log10(W_SH(i)) < 20.3))
count(30) = count(30) + 1;
end
end
for i=1:30
prob(i) = count(i)/sum(count);
prob_dens(i) = prob(i)/bin(i);
end
% Check
sum(prob_dens.*bin);
prob_dens_all(i,:) = prob_dens(:);
%end
prob_dens_mean = zeros(1,30);
for i = 1 : 30
prob_dens_mean(1,i) = mean(prob_dens_all(:,i));
%prob_dens_std(1,i) = std(prob_dens_all(:,i));
end
% Plot
best_fit = polyfit(bin,log10(prob_dens_mean),11)
h = figure;
loglog(bin,prob_dens_mean,'ro','MarkerSize',10)
hold on;
plot(best_fit,'b')
t = title('Event Power Distribution, SHem, August 2005');
set(t, 'FontWeight', 'bold', 'FontSize', 12)
set(gca, 'FontWeight', 'bold', 'FontSize', 12)
xlabel('Event Power (W)');
ylabel('Probability Density');
print -dpng SHem_Wattage_PDF_AUG2005.png
axis([1e10 1e20 1e-28 1e-12]) after hold on

Best Fit Line with logarithmic axes (MATLAB)

I am trying to plot a best fit line on a probability density function with logarithmic axes. The Y-axis (PDF) is 10^-12 to 10^-28, while the X-axis is 10^10 to 10^20. I've tried polyfit, with no luck. Any ideas? Attached is my code.
Thanks,
Kevin
clc;
clear all;
load Aug2005_basin_variables.mat
% Initialize
j_len = length(W_SH);
prob_dens_all = zeros(j_len,30);
ii = 1 : j_len;
count(1:30) = 0;
bin(1:30) = 0;
for i = 1 : 30
bin(i) = 10^(11 + (0.3*i));
end
% Bin the Watts
for i = 1 : j_len
if((log10(W_SH(i)) >= 11) && (log10(W_SH(i)) < 11.3))
count(1) = count(1) + 1;
end
if((log10(W_SH(i)) >= 11.3) && (log10(W_SH(i)) < 11.6))
count(2) = count(2) + 1;
end
if((log10(W_SH(i)) >= 11.6) && (log10(W_SH(i)) < 11.9))
count(3) = count(3) + 1;
end
if((log10(W_SH(i)) >= 11.9) && (log10(W_SH(i)) < 12.2))
count(4) = count(4) + 1;
end
if((log10(W_SH(i)) >= 12.2) && (log10(W_SH(i)) < 12.5))
count(5) = count(5) + 1;
end
if((log10(W_SH(i)) >= 12.5) && (log10(W_SH(i)) < 12.8))
count(6) = count(6) + 1;
end
if((log10(W_SH(i)) >= 12.8) && (log10(W_SH(i)) < 13.1))
count(7) = count(7) + 1;
end
if((log10(W_SH(i)) >= 13.1) && (log10(W_SH(i)) < 13.4))
count(8) = count(8) + 1;
end
if((log10(W_SH(i)) >= 13.4) && (log10(W_SH(i)) < 13.7))
count(9) = count(9) + 1;
end
if((log10(W_SH(i)) >= 13.7) && (log10(W_SH(i)) < 14.0))
count(10) = count(10) + 1;
end
if((log10(W_SH(i)) >= 14.0) && (log10(W_SH(i)) < 14.3))
count(11) = count(11) + 1;
end
if((log10(W_SH(i)) >= 14.3) && (log10(W_SH(i)) < 14.6))
count(12) = count(12) + 1;
end
if((log10(W_SH(i)) >= 14.6) && (log10(W_SH(i)) < 14.9))
count(13) = count(13) + 1;
end
if((log10(W_SH(i)) >= 14.9) && (log10(W_SH(i)) < 15.2))
count(14) = count(14) + 1;
end
if((log10(W_SH(i)) >= 15.2) && (log10(W_SH(i)) < 15.5))
count(15) = count(15) + 1;
end
if((log10(W_SH(i)) >= 15.5) && (log10(W_SH(i)) < 15.8))
count(16) = count(16) + 1;
end
if((log10(W_SH(i)) >= 15.8) && (log10(W_SH(i)) < 16.1))
count(17) = count(17) + 1;
end
if((log10(W_SH(i)) >= 16.1) && (log10(W_SH(i)) < 16.4))
count(18) = count(18) + 1;
end
if((log10(W_SH(i)) >= 16.4) && (log10(W_SH(i)) < 16.7))
count(19) = count(19) + 1;
end
if((log10(W_SH(i)) >= 16.7) && (log10(W_SH(i)) < 17.0))
count(20) = count(20) + 1;
end
if((log10(W_SH(i)) >= 17.3) && (log10(W_SH(i)) < 17.6))
count(21) = count(21) + 1;
end
if((log10(W_SH(i)) >= 17.6) && (log10(W_SH(i)) < 17.9))
count(22) = count(22) + 1;
end
if((log10(W_SH(i)) >= 17.9) && (log10(W_SH(i)) < 18.2))
count(23) = count(23) + 1;
end
if((log10(W_SH(i)) >= 18.2) && (log10(W_SH(i)) < 18.5))
count(24) = count(24) + 1;
end
if((log10(W_SH(i)) >= 18.5) && (log10(W_SH(i)) < 18.8))
count(25) = count(25) + 1;
end
if((log10(W_SH(i)) >= 18.8) && (log10(W_SH(i)) < 19.1))
count(26) = count(26) + 1;
end
if((log10(W_SH(i)) >= 19.1) && (log10(W_SH(i)) < 19.4))
count(27) = count(27) + 1;
end
if((log10(W_SH(i)) >= 19.4) && (log10(W_SH(i)) < 19.7))
count(28) = count(28) + 1;
end
if((log10(W_SH(i)) >= 19.7) && (log10(W_SH(i)) < 20.0))
count(29) = count(29) + 1;
end
if((log10(W_SH(i)) >= 20.0) && (log10(W_SH(i)) < 20.3))
count(30) = count(30) + 1;
end
end
for i=1:30
prob(i) = count(i)/sum(count);
prob_dens(i) = prob(i)/bin(i);
end
% Check
sum(prob_dens.*bin);
prob_dens_all(i,:) = prob_dens(:);
%end
prob_dens_mean = zeros(1,30);
for i = 1 : 30
prob_dens_mean(1,i) = mean(prob_dens_all(:,i));
%prob_dens_std(1,i) = std(prob_dens_all(:,i));
end
% Plot
best_fit = polyfit(bin,log10(prob_dens_mean),11)
h = figure;
loglog(bin,prob_dens_mean,'ro','MarkerSize',10)
hold on;
plot(best_fit,'b')
t = title('Event Power Distribution, SHem, August 2005');
set(t, 'FontWeight', 'bold', 'FontSize', 12)
set(gca, 'FontWeight', 'bold', 'FontSize', 12)
xlabel('Event Power (W)');
ylabel('Probability Density');
print -dpng SHem_Wattage_PDF_AUG2005.png
I don't have your data, but here is an example using some random normally-distributed random data
x=randn(1000,1)+5; % create some data, keep numbers positive by adding 5
[n,xb]=hist(x); % Create the histogram
n = n/sum(n); % convert counts to a pdf
p=polyfit(log(xb), log(n), 3); % Do a 3rd order fit
loglog(xb,n, '*-', xb, exp(polyval(p, log(xb))), 'r')
grid on
legend('PDF', 'Fit', 0)

change name of a variable inside a loop [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to concatenate a number to a variable name in MATLAB?
It must be easy but I just cannot find it in help!
I am operating with a vector x for 10 loops (for example) and at the end I want to concatenate all the results in a matrix 10by10. In order to do that I have to name them x1,x2,x3 etc. how can I do this?
Edit: A portion of my code thus far (copied from comments):
x = [0,0,0,1,0,0,1,0];
for k = 1:50
if x(1,8) ==1 && x(1,1)==1 && x(1,2)==1
x(1,1)=0;
elseif x(1,8) ==1 && x(1,1)==1 && x(1,2)==0
x(1,1)=0;
elseif x(1,8) ==1 && x(1,1)==0 && x(1,2)==1
x(1,1)=0;
elseif x(1,8) ==1 && x(1,1)==0 && x(1,2)==0
x(1,1)=1;
elseif x(1,8) ==0 && x(1,1)==1 && x(1,2)==1
x(1,1)=1;
elseif x(1,8) ==0 && x(1,1)==1 && x(1,2)==0
x(1,1)=1;
elseif x(1,8) ==0 && x(1,1)==0 && x(1,2)==1
x(1,1)=1;
end
...etc...
disp(x)
You should preallocate a matrix before your loop, and in the loop you just insert the vectors directly in the columns (or rows). Like:
A= zeros(10, 10);
for k in 1: 10
A(:, k)= %# result of your processing
end