Comparing values from structure to a scalar

for i=1:15
A(i).A = [randi(10, 10, 1), rand(10,1)];
for j=1:10
mpc = loadcase('case14');
results(i).A(j) = runpf(mpc);
end
end
Is there a way to add the following constraint in the for loop (the one with j=1:m):
if results(i).A.bus(:,8)>1.1
A(i).A(j,2) = rand(10,1);
results(i).A(j) = runpf(mpc);
end
I tried with that code above and it didn't work, those results were higher than 1.1 again.

답변 (1개)

James Tursa
James Tursa 2015년 9월 11일
편집: James Tursa 2015년 9월 11일

0 개 추천

Considering this line:
if results(i).A.bus(:,8)>1.1
It looks like a vector expression to me, which means it is equivalent to:
if all(results(i).A.bus(:,8)>1.1)
Was that your intention? Or was it your intention to take some action for each individual result > 1.1 ?
Also, this action doesn't look right:
A(i).A(j,2) = rand(10,1)
It looks like you are assigning a 10 x 1 column vector to a scalar element.

댓글 수: 4

Drazen Tubic
Drazen Tubic 2015년 9월 11일
well my intention is to change all those values in A(i).A that are causing results(i).A.bus(:,8) to be higher than 1.1. For example, in first iteration, A(1).A(1,2) is causing results(1).A(1).bus(:,8). In that case if any of the values from results(1).A(1).bus(:,8) is higher than 1.1, A(1).A(1,2) needs to be changed.
Drazen Tubic
Drazen Tubic 2015년 9월 11일
And as for that assigning, i made a mistake, it should be equal to a random scalar: A(i).A(j,2) = rand(1)
Does this do what you want?
if any(results(i).A.bus(:,8)>1.1)
Drazen Tubic
Drazen Tubic 2015년 9월 11일
unfortunately no, some results in results(i).A.bus(:,8) are still higher than 1.1 after i did that.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2015년 9월 11일

편집:

2015년 9월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by