How can I make the vector output always a column vector?

1 view (last 30 days)
I'm having trouble with a problem where I need the output vector to be a column vector always. The output sometimes provided as row vectors and in the iteration stops as vector dimensions are not the same. The algorithm stops after sometime when the output takes row vector. Please help me how to fix the out of a vector always as a column vector. here is one example.
$x{n+1}=z{n}$ is not predictable. it gives sometimes as a row vector and sometimes as a column vector. it supposed to finish all 2000 iterations, but it will give me error sometimes
N=100;
matrixSize=N;
x{1}=fix(randi([5,5],N,1));
W=fix(randi([2,2],N,1));
for n=1:200;
y{n}=x{n}+W;
for j=1:N;
if y{n}(j,:)<0;
z{n}(j,:)=100;
else
z{n}(j,:)=99;
end
x{n+1}=z{n};
end
end
  1 Comment
Bruno Luong
Bruno Luong on 26 Oct 2018
Your code has plenty of row vectors, and not column vectors.
a(j,:) % <- row
a(:,j) % <- column
Unless if you leave in a parallel universe than the rest of us.

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 26 Oct 2018
N=100;
matrixSize=N;
x{1}=fix(randi([5,5],N,1));
W=fix(randi([2,2],N,1));
for n=1:200;
y{n}=x{n}'+W;
for j=1:N;
if y{n}(j,:)<0;
z{n}(j,:)=100;
else
z{n}(j,:)=99;
end
x{n+1}=z{n};
end
end
  2 Comments
Dinoma Degefa
Dinoma Degefa on 26 Oct 2018
Dear Sir, here is my code. but not working. after going a few iterations it will stop as the outcome for q4{n,:}=RR{n,:} is a row vector. run it reputedly you will see.
N=100;
matrixSize=N;
x{1,:}=fix(randi([50,50],N,1));
x{2,:}=fix(randi([200,200],N,1));
for n=2:2000;
beta(n)=(1/3)-(1/(n+2));
WWW{n,:}=beta(n)*x{n,:}-beta(n)*x{n-1,:};
WW1{n,:}=x{n,:}+WWW{n,:};
AA=eye(N);
y{n,:}=AA*x{n,:};
R{n,:}=AA*WW1{n,:};
for j=1:N;
if norm(R{n,:}(j,:))<1;
RR{n,:}(j,:)=R{n,:}(j,:);
else if norm(R{n,:}(j,:))<=2 & norm(R{n,:}(j,:))>=1;
if R{n,:}(j,:)<0;
RR{n,:}(j,:)=-1;
else if R{n,:}(j,:)>0;
RR{n,:}(j,:)=1;
else RR{n,:}(j,:)=0;
end
end
else if R{n,:}(j,:)-1<0;
RR{n,:}(:,j)=-1;
else if R{n,:}(j,:)-1>0;
RR{n,:}(j,:)=y{n,:}(j,:)-1;
else RR{n,:}(j,:)=0;
end
end
end
end
end
q4{n,:}=RR{n,:};
x{n+1,:}= y{n,:}-RR{n,:}; %(I-proxg2)Ax(n)
end
toc;

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!