Borrar filtros
Borrar filtros

create a changing vector after each iteration

1 visualización (últimos 30 días)
Michael
Michael el 25 de Oct. de 2013
Respondida: Andrei Bobrov el 25 de Oct. de 2013
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 comentario
Azzi Abdelmalek
Azzi Abdelmalek el 25 de Oct. de 2013
Editada: Azzi Abdelmalek el 25 de Oct. de 2013
Can you explain the problem with your code?

Iniciar sesión para comentar.

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 25 de Oct. de 2013
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];

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by