Using the find function in a for-loop: Need to solve an error - "Unable to perform assignment because the left and right sides have a different number of elements"
Show older comments
Hi!
I'm trying to replace uncorrected GNSS coordinates with their PPK solution coordinate. My code hinges on a for-loop that uses the find function to replace the uncorrected GNSS coordinate with the correct PPK coordinate. The find function is used to identify corresponding time-stamps between the two files.
I am trying to diagnose an error thrown by this loop. The error is: "Unable to perform assignment because the left and right sides have a different number of elements." The for-loop will run until it finally hits an error, so I know that the code at least somewhat works. I need to either:
- Figure out what is throwing the error and redraw the code such that it doesn't throw this error, or
- Figure out how to write the code such that it skips the error.
The following is the for-loop that is proving problematic. If it would be helpful to have my full code and text files, please let me know.
m = NaN(length(gp2_addon),1);
n = NaN(length(gp2_addon),1);
%test for-loop
tolerance = 1*10^-15;
for i = 1:length(gp2_addon)
[m(i),n(i)] = find(abs(Rover(:,1)-gp2(i,1))<=tolerance);
gp2(i,6)=Rover(m(i),2);%corrected latitude
gp2(i,7) = Rover(m(i),3);%corrected longitude
end
For the code:
m and n are two vectors in which the indicies from the find function are stored.
Rover is the PPK solution and gp2 is the original uncorrected coordinates.
The tolerance is set for decimal time - both files utilize a time stamp rounded to 15 decimal places.
The line that specifically throws the error is [m(i),n(i)]=find...
What I suspect is going on:
I think the find function is not finding a match in the instances where it throws the error. In this instance, it comes up empty and replaces m(i) and n(i) with a blank set.
Thank you so much for your time!
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!