Comparing values from structure to a scalar
Ältere Kommentare anzeigen
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.
Antworten (1)
James Tursa
am 11 Sep. 2015
Bearbeitet: James Tursa
am 11 Sep. 2015
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 Kommentare
Drazen Tubic
am 11 Sep. 2015
Drazen Tubic
am 11 Sep. 2015
James Tursa
am 11 Sep. 2015
Does this do what you want?
if any(results(i).A.bus(:,8)>1.1)
Drazen Tubic
am 11 Sep. 2015
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!