I am trying to make a colon that starts from 0.4 to 1 and then from 1 to 0.4 , which i used pf(j)=0.4+0.01*(j-1); if there is another method that I can do it, it might help me significantly plot such function.
Index exceeds the number of array elements
2 views (last 30 days)
Show older comments
clc
clear
r=0;x=9;
wg=40e6; vo=30e3;voa=0;
for j=1:121
pf(j)=0.4+0.01*(j-1);
if pf<=1
cons(j)=acos(pf(j));
elseif pf>1
cons(j)=-acos(2-pf(j));
end
ia(j)=(wg./(sqrt(3).*vo.*abs(pf(j)))).*(cos(acos(pf(j)))+sin(cons(j)).*i);
eph(j)=(vo./(sqrt(3))).*(cosd(voa)+sind(voa).*i)+ia(j)*(r+i*x);
E(j)=sqrt(3).*abs(eph(j));
Ifex(j)=abs(E(j))./3464.1;
iax(j)=abs(ia(j));
end
plot(Ifex,iax)
grid
xlabel('Field current (A)')
ylabel('Armature current (A)')
title('V curve of synch. generator')
if i juse else only in the if statement, the code will run but the plot will be incomplete, and if i put elseif pf>1, I get an error
Accepted Answer
Voss
on 7 Dec 2021
In your if and elseif conditions you are comparing the vector pf with the scalar 1. You should use pf(j) instead of pf in those places, in order to compare the jth element of pf with 1.
(And, as you point out, the elseif can be replaced with just else. After you change pf to pf(j), the else block will be executed for some j, and cons will have the same size as pf, avoiding this error.)
0 Comments
More Answers (0)
See Also
Categories
Find more on Fit Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!