필터 지우기
필터 지우기

create a changing vector after each iteration

조회 수: 1 (최근 30일)
Michael
Michael 2013년 10월 25일
답변: Andrei Bobrov 2013년 10월 25일
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
Azzi Abdelmalek 2013년 10월 25일
편집: Azzi Abdelmalek 2013년 10월 25일
Can you explain the problem with your code?

댓글을 달려면 로그인하십시오.

답변 (1개)

Andrei Bobrov
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];

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by