Error updating Scatter: Data lengths must match - but they do...

8 views (last 30 days)
Hello,
I am trying to use a continuous value change slider UI to add a fourth dimension (time) to a graphic showing the position of GNSS satellites used in a navigation solution.
function myslider(gnss, truth)
[x_earth,y_earth,z_earth] = ellipsoid(0,0,0,6378137,6378137,6356752.31424518,30);
figure(); surf(x_earth,y_earth,z_earth, 'EdgeColor', '#0072BD', 'FaceColor', '#0072BD',...
'FaceAlpha', 0.3); hold on; % plot the earth
scatter3(truth.pos(1),truth.pos(2),truth.pos(3),85,'MarkerFaceColor','y','MarkerEdgeColor','k','Marker','p'); % add truth
u_tow = unique(gnss.tow);
slide = min(u_tow):1:max(u_tow);
colour = gnss.gnssId; % add a unique color to identify each constellation
colour(colour(:,1)==0,1:3) = repmat([0, 0.4470, 0.7410], sum(colour(:,1)==0),1);
colour(colour(:,1)==2,:) = repmat([0.8500, 0.3250, 0.0980], sum(colour(:,1)==2),1);
colour(colour(:,1)==6,:) = repmat([0.4660, 0.6740, 0.1880], sum(colour(:,1)==6),1);
hplot = scatter3(gnss.satPos(gnss.tow == slide(1),1),gnss.satPos(gnss.tow == slide(1),2), ...
gnss.satPos(gnss.tow == slide(1),3), ones(sum(gnss.tow == slide(1)),1)*25,colour(gnss.tow == slide(1),:), 'filled');
h = uicontrol('style','slider','units','pixel','position',[20 20 250 20], 'Min',1,'Max',numel(u_tow),...
'value', 1,'SliderStep',[0.001 0.5]);
addlistener(h,'ContinuousValueChange',@(hObject, event) makeSlidePlot(hObject,hplot,slide,gnss,colour,truth));
end
function makeSlidePlot(hObject,hplot,slide,gnss,colour,truth) %truth added to attempt to stop error when no satellites available
n = get(hObject,'Value'); n=round(n);
set(hplot,'xdata',[truth.pos(1); gnss.satPos(gnss.tow == slide(n),1)]','ydata',[truth.pos(2); gnss.satPos(gnss.tow == slide(n),2)]','zdata',[truth.pos(3); gnss.satPos(gnss.tow == slide(n),3)]', 'cdata', [1 1 0; colour(gnss.tow == slide(n),1:3)]);
set(gca,'XLim',[-10000000 30000000],'YLim',[-10000000 30000000],'ZLim',[-10000000 30000000]);
drawnow;
end
The function is able to plot the initial data with no issues, but when updating the values it gives the following error:
  • Warning: Error updating Scatter. Data lengths must match.
This happens in the function makeSlidePlot on the line starting with set(hplot
I've tried looking at which values are assigned to 'xdada'/'ydata'/'zdata'/'cdata' when this error occurs and can't figure out why they won't work. As an example, some values are below (typed by hand, not actual matlab code just used for easy reading):
x_data = [4.001157205000000e+06;2.572546709530618e+07;8.678234779917900e+06;3.952943480663775e+06]; % 4x1
y_data = [-1.430807600000000e+04;3.867255631461378e+06;-1.347380604311346e+07;1.025898885350909e+07]; % 4x1
z_data = [4.950553757000000e+06;6.564856076579228e+06;2.489296866319447e+07;2.302901468983255e+07]; % 4x1
c_data = [1.0000 1.0000 0; ...
0 0.4470 0.7410; ...
0.8500 0.3250 0.0980; ...
0.4660 0.6740 0.1880]; % 4x3
If you can provide some insight it would be very appreciated. Or if you would prefer that I simplify the code and names of variables please let me know.
Thanks so much in advance!! (BTW: using Matlab R2019b).
EDIT: As per the comment, attached is the data for gnss and truth and an image of the error/warningIn RunSimLite (line 52)  Warning: Error updating Scatter.   Data lengths must match.   > In defaulterrorcallback (line 12)   In RunSimLite>makeSlidePlot (line 191)   In RunSimLite>@(hObject,event)makeSlidePlot(hObject,hplot,slide,gnss,colour,truth) (line 183)
  3 Comments
Megan Jurczak
Megan Jurczak on 6 Aug 2021
@Cris LaPierre Thank you so much for your comment :) I have updated the question as per your suggestions. Hopefully this is sufficient in finding a solution
Cris LaPierre
Cris LaPierre on 6 Aug 2021
Edited: Cris LaPierre on 6 Aug 2021
I do not get an error when running these functions with this data in R2019b. I scrolled through the entire dataset.
Try running just the following code in your MATLAB with the data you have shared and see if it works.
load matlabQuestion.mat
myslider(gnss, truth)
function myslider(gnss, truth)
[x_earth,y_earth,z_earth] = ellipsoid(0,0,0,6378137,6378137,6356752.31424518,30);
figure('visible','on');
surf(x_earth,y_earth,z_earth, 'EdgeColor', '#0072BD', 'FaceColor', '#0072BD',...
'FaceAlpha', 0.3); hold on; % plot the earth
scatter3(truth.pos(1),truth.pos(2),truth.pos(3),85,'MarkerFaceColor','y','MarkerEdgeColor','k','Marker','p'); % add truth
u_tow = unique(gnss.tow);
slide = min(u_tow):1:max(u_tow);
colour = gnss.gnssId; % add a unique color to identify each constellation
colour(colour(:,1)==0,1:3) = repmat([0, 0.4470, 0.7410], sum(colour(:,1)==0),1);
colour(colour(:,1)==2,:) = repmat([0.8500, 0.3250, 0.0980], sum(colour(:,1)==2),1);
colour(colour(:,1)==6,:) = repmat([0.4660, 0.6740, 0.1880], sum(colour(:,1)==6),1);
hplot = scatter3(gnss.satPos(gnss.tow == slide(1),1),gnss.satPos(gnss.tow == slide(1),2), ...
gnss.satPos(gnss.tow == slide(1),3), ones(sum(gnss.tow == slide(1)),1)*25,colour(gnss.tow == slide(1),:), 'filled');
h = uicontrol('style','slider','units','pixel','position',[20 20 250 20], 'Min',1,'Max',numel(u_tow),...
'value', 1,'SliderStep',[0.001 0.5]);
addlistener(h,'ContinuousValueChange',@(hObject, event) makeSlidePlot(hObject,hplot,slide,gnss,colour,truth));
end
function makeSlidePlot(hObject,hplot,slide,gnss,colour,truth) %truth added to attempt to stop error when no satellites available
n = get(hObject,'Value'); n=round(n);
set(hplot,'xdata',[truth.pos(1); gnss.satPos(gnss.tow == slide(n),1)]','ydata',[truth.pos(2); gnss.satPos(gnss.tow == slide(n),2)]','zdata',[truth.pos(3); gnss.satPos(gnss.tow == slide(n),3)]', 'cdata', [1 1 0; colour(gnss.tow == slide(n),1:3)]);
set(gca,'XLim',[-10000000 30000000],'YLim',[-10000000 30000000],'ZLim',[-10000000 30000000]);
drawnow;
end

Sign in to comment.

Accepted Answer

Dave B
Dave B on 6 Aug 2021
Edited: Dave B on 6 Aug 2021
I bet this is SizeData, you're setting it initially to:
ones(sum(gnss.tow == slide(1)),1)*25
So it matches the other data properties in length. But then later you're changing the length of the others and skipping SizeData.
I think if you don't expect to change sizedata, you could just set it to 25 initially, if you set it to a scalar, then Scatter should be okay with expanding it to match the length of the other data properties.
  1 Comment
Megan Jurczak
Megan Jurczak on 9 Aug 2021
Absolutely perfect, thanks so much! Such a silly mistake on my part and I'm happy to finally have it solved. I really appreciate your effort and the concise answer :)

Sign in to comment.

More Answers (0)

Categories

Find more on Satellite Mission Analysis in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!