scatter3 based on one of the variable's value

2 views (last 30 days)
Hello everybody! I am trying to represent some points in 3D and change their color based on the value of the third variable (criticality). When I do this I get the following error:
Error using scatter3
Dimensions of arrays being concatenated are not consistent.
Even though the dimension is correct because I am using as colormap one of the variables. The variables are 1x30 double.
Here are the variables and the code I used:
x = [0.1750 0.4210 0.8350 0.5080 0.6310 0.3400 0.6250 0.7390 0.1120 0.6760 0.8590 0.6730 0.3130 0.7060 0.1780 0.4420 0.7960 0.3250 0.3190 0.1990 0.1120 0.6190 0.2620 0.3010 0.4750 0.1390 0.5380 0.2110 0.5500 0.6370];
y = [0.5180 0.7520 0.2000 0.4310 0.3110 0.2690 0.3410 0.4640 0.5030 0.6110 0.5210 0.7250 0.3560 0.8720 0.2210 0.7130 0.5180 0.6290 0.3050 0.3500 0.8120 0.9410 0.4400 0.7310 0.8720 0.8870 0.2630 0.2270 0.3290 0.8720];
criticality = [0.0000 0.0006 0 0 0 0 0 0 0.0001 0 0 0 0 0.0797 0 0.0051 0.0000 0.0027 0 0.6491 0.0000 0.0001 0.2592 0.0000 0.0000 0.0000 0 0 0 0.0034];
scatter3(x,y,criticality,[],criticality,'filled')
Does anyone know what could be happening? Thank you very much in advance
  3 Comments
Cris LaPierre
Cris LaPierre on 17 May 2023
It works here (R2023a). What version of MATLAB are you using?
Star Strider
Star Strider on 17 May 2023
This has been going on for a while. (I believe he has R2022b, however I don’t remember.)
I suggested doing a which hunt for overshadowed functions, and finally restordeefaultpath and rehash toolboxcache, all to no avail.
OP is probably going to have to uninstall and reinstall MATLAB. (That was my final suggestion before I deleted my answer a few hours ago, since it didn’t solve the probem.)

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 17 May 2023
With old enough versions of MATLAB you need to pass in column vectors, especially for the color information.
  2 Comments
DGM
DGM on 17 May 2023
Edited: DGM on 17 May 2023
I can't find the change in the release notes, but for what it's worth, the given example runs in R2009b.
Walter Roberson
Walter Roberson on 17 May 2023
Note: if you just happen to have 3 points, and so have a vector of 3 color values, then if you pass that vector as a row vector, then scatter will interpret it as being an RGB triple to apply to all three points. The test is "if number of columns is 3 then this is RGB information", rather than "if the number of columns is the same as the number of x coordinates then this is per-point information"

Sign in to comment.

Categories

Find more on Colormaps 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!