0
votes

i am trying to run a series of equations by calling certain data points from my matrix over a series of combinations. I am essentially comparing each data set against the others, one at a time, over a series of different errors (the errors are the psivct array).

i am getting a "subscripted assignment dimension mismatch" error for the final line of my code and i don't know what to do about it....? I have done my best to comment out my code for clarity...

it works fine when i am only comparing two sets, but when i add the third, i get this error. Any insight?

Thanks again in advance for any help :)

datamatrix=[674 0 6049 46489;760 180 90735 120980; 650 0 12500 61000]; %data points velocity,
heading, x location, y location
psivct=[-90, -45, 0, 45, 90];%degrees degrees of error 
psidot=3; %degrees/sec rate of error change
d=500; %distance apart for a problem, in feet
Nr_AC=3; %number of aircrafts in sector


for c1 = 1:size(psivct,2)
    psi1=psivct(c1); %for loop to run through array of blunder errors

    for c2=1:Nr_AC-1; %for loop to account for all pairs and avoid same pairs twice

        for c3=c2+1:Nr_AC; %for loop to help avoid account for hte same pairs twice


k1=datamatrix(c2,1).*cosd(datamatrix(c2,2)+psi1)-datamatrix(c2,1)*cosd(datamatrix(c3,2));

k2=((datamatrix(c2,1)/psidot).*(sind(datamatrix(c2,2)+psi1)-sind(datamatrix(c2,2))))
cosd(datamatrix(c2,2)+psi1)*datamatrix(c2,1).*(psi1./psidot)+datamatrix(c2,3)-datamatrix(c3,3);

k3=datamatrix(c2,1).*sind(datamatrix(c2,2)+psi1)-datamatrix((c3),1)*sind(datamatrix((c3),2));

k4=(datamatrix(c2,1)/psidot)*(cosd(datamatrix(c2,2))-cosd(datamatrix(c2,2)+psi1))
sind(datamatrix(c2,2)+psi1)*datamatrix(c2,1).*(psi1./psidot)+datamatrix(c2,4)-datamatrix(c3,4);

k5=k1.^2+k3.^2; %"a" in the polynomial
k6=2*(k1.*k2+k3.*k4); %"b" in the polynomial
k7=k3.^2+k4.^2-500; %"c" in the polynomial
p = [k5 k6 k7]; % creating hte polynomial
r = roots(p); %solving for roots
rr(:,c1,c2,c3)=real(r)/60 %getting real answers
end;
end;
end;
1
can you show the output of a whos just before that last line generating the error? - Benoit_11
Your variables are: Nr_AC c3 k1 k4 k7 psidot rr c1 d k2 k5 p psivct c2 datamatrix k3 k6 psi1 r - Caitlin Surakitbanharn
oh I mean what do you get when you type 'whos' in the Command window? - Benoit_11
You get an error because your r is empty when c1=3, c2=1, c3=3. r is empty because p=[0 0 -500], it has no roots. From here, you have to take on the problem. Also, this is basic debugging. You need to learn this to solve your problems more efficiently. - Autonomous
Nr_AC 1x1 8 double c 20x1 2354 cell c1 1x1 8 double c2 1x1 8 double c3 1x1 8 double d 1x1 8 double datamatrix 3x4 96 double k1 1x1 8 double k2 1x1 8 double k3 1x1 8 double k4 1x1 8 double k5 1x1 8 double k6 1x1 8 double k7 1x1 8 double p 1x3 24 double psi1 1x1 8 double psidot 1x1 8 double psivct 1x5 40 double r 0x1 0 double rr 4-D 288 double - Caitlin Surakitbanharn

1 Answers

0
votes

Your problem comes from the r vector: it sometimes is empty because the polynomial doesn't have roots. Then r is a 0x1 vector, and you're assigning it to a 2x1 vector (r(:,c1,c2,c3) is a 2x1 vector because the first time you assign r to it, Matlab creates the matrix rr and initializes its size).

You would need a check on the existence of roots before you do the assignment. Something like

if (~isempty(r))
  rr(:,c1,c2,c3)=real(r)/60; %getting real answers
end

As a general rule, it would be good to figure out how the size of rr before starting your loops, and initializing rr. It results in better performance, and 'cleaner' code, since Matlab is not trying to resize the 4-D matrix all the time.

Also, be careful in your lines for k2 and k4, the sind and cosd are not taken into account right now. If you wanted to continue the line (and multiply the first line by the second, you should do:

k2=((datamatrix(c2,1)/psidot).*(sind(datamatrix(c2,2)+psi1)-sind(datamatrix(c2,2)))) * ...
cosd(datamatrix(c2,2)+psi1)*datamatrix(c2,1).*(psi1./psidot)+datamatrix(c2,3)-datamatrix(c3,3);

with * or .* depending on what you want to accomplish