create a changing vector after each iteration
    3 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hi,
i want create a changing vector. Depending on a matrix the values of PV, WP, WS, B and K differ in 0 and 1.
Here is the code:
UM=[1,1,1,1,1;1,0,0,0,0;0,1,0,0,0;0,0,1,0,0;0,0,0,1,0;0,0,0,0,1;1,1,0,0,0;1,0,1,0,0;1,0,0,1,0;1,0,0,0,1;0,1,1,0,0;0,1,0,1,0;0,1,0,0,1;0,0,1,1,0;0,0,1,0,1;0,0,0,1,1;1,1,1,0,0;1,1,0,1,0;1,1,0,0,1;0,1,1,1,0;0,1,1,0,1;0,0,1,1,1;0,1,1,1,1;1,0,1,1,1;1,1,0,1,1;1,1,1,0,1;1,1,1,1,0;0,0,0,0,0];
va = zeros(10,1);
nRows = 28;
nCols = 5;
M = cell(28,2);
for rId = 1:28
    M{rId} =  UM(rId,:);
    PV = M{rId,1}(1);
    B = M{rId,1}(2);
    WP = M{rId,1}(3);
    K = M{rId,1}(4);
    WS = M{rId,1}(5);  
          if PV == 1
              10 = va(2);
              10 = va(7);
          else PV == 0
              0 = va(2);
              inf = va(7);
          end; 
          if WS == 1
              250 = va(1);
              250 = va(6);
          else WS == 0
              0 = va(1);
              inf = va(6);
          end;
          if B == 1
              6 = va(3);
              6 = va(8);
          else B == 0
              0 = va(3);
              inf = va(8);
          end;
          if WP == 1
              8 = va(4);
              8 = va(9);
          else WP == 0
              0 = va(2);
              15 = va(7);
          end;
          if K == 1
             6 = va(5);
             6 = va(10);
          else K == 0
              0 = va(5);
              inf = va(10);
          end;
end;
My aim is to create the vector va(10,1) with the new values given from the if constraints.
1 件のコメント
  Azzi Abdelmalek
      
      
 2013 年 10 月 25 日
				
      編集済み: Azzi Abdelmalek
      
      
 2013 年 10 月 25 日
  
			Can you explain the problem with your code?
回答 (1 件)
  Andrei Bobrov
      
      
 2013 年 10 月 25 日
        u = circshift(UM,[0 1]);
a=[250 10 6 8 6];
va = bsxfun(@times,u,a);
v2 = va;
v2(v2==0) = inf;
va=[va,v2];
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


