Error updating Scatter: Data lengths must match - but they do...
Afficher commentaires plus anciens
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/warning%20%20Warning:%20Error%20updating%20Scatter.%20%20%20Data%20lengths%20must%20match.jpeg)
%20%20Warning:%20Error%20updating%20Scatter.%20%20%20Data%20lengths%20must%20match.jpeg)
3 commentaires
Cris LaPierre
le 6 Août 2021
It would be helpful if you could share the variables gnss and truth, and enough working code to reproduce the issue.
Could you also please share the complete error message (all the red text)?
Megan Jurczak
le 6 Août 2021
Cris LaPierre
le 6 Août 2021
Modifié(e) : Cris LaPierre
le 6 Août 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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Earth and Planetary Science dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!