In an assignment A(I) = B, the number of elements in B and I must be the same.

1 visualizzazione (ultimi 30 giorni)
Hi all I'm facing some error made me crazy :S
I'm using that code
for fa=10:10:50
V1=(V/sqrt(3)/50)*fa; % voltage changes with frequency
ns1=(60*fa)/p;
ws1=(2*pi*fa)/p;
n1=0:5:ns1;
s1=(ns1-n1)./ns1;
T1=(3*V1.^2./(ws1))*(R2./s1)./((R1+(R2./s1)).^2+((fa/50)*(x1+x2))^2);
plot(n1,T1)
hold on
[ni,Ti] = intersections(n1,T1,ng,Tl);
y(cnta) = Ti;
x(cnta) = ni;
cnta=cnta+1;
end
for fb=60:10:100
V2=V/sqrt(3) ; % in high frequency voltage is const
ns2=(60*fb)/p;
ws2=(2*pi*fb)/p;
n2=0:5:ns2;
s2=(ns2-n2)./ns2;
T2=(3*V2.^2./(ws2))*(R2./s2)./((R1+(R2./s2)).^2+((fb/50)*(x1+x2))^2);
plot(n2,T2,'r')
hold on
[nw,Tw] = intersections(n2,T2,ng,Tl);
z(cntb) = Tw;
c(cntb) = nw;
cntb=cntb+1;
end
and error is
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in Untitled (line 39) z(cntb) = Tw;
note that i copied the code from above for loop to the second for loop and the error in the second one :( and all variables are declared before :)
waiting for ur help and thanks in advance :)

Risposte (1)

Matt Fig
Matt Fig il 1 Dic 2012
Modificato: Matt Fig il 1 Dic 2012
Have a look at this:
A([1 2 3]) = [8 7 6 8 7 9] % Error
A([1 2 3]) = [8 7] % Error
A([1 2 3]) = [8 7 6] % No error
We get the same error with both of the first assignment attempts. So in your code, cntb has 1 element (as far as I can see) and Tw has more or less than 1 element. That is where you need to start your investigation of the code.
z(cntb) = Tw % numel(Tw) ~= numel(cntb)
  7 Commenti
Matt Fig
Matt Fig il 1 Dic 2012
Did you read the help for that function before you used it? The author provides a help file, which you can read by typing this:
help intersections
I suggest you get in the habit of reading about the functions you are using! According to the help,
% Computes the (x,y) locations where two curves intersect.
So if the curves intersect at more than one location, you will get more than one x,y pair. If the curves intersect in NO locations, x and y will be empty. Now you need to figure out what to do in either case before you try to pass the results to z.
if numel(Tw)==1
z(cntb) = Tw; % For example....
else
% Whatever you want to do here.
end
ahmed
ahmed il 1 Dic 2012
ok i will try to read the help and sorry if i made u busy

Accedi per commentare.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by