If clr is a cell array of strings, the length of clr must be equal to the length of x, y and z.
1 view (last 30 days)
Show older comments
Hello, I have problem in gscatter3(). The link of gscatter3 is as follow:
Thanks in advance for any help!
>> stage265_tran=stage265';
>> [~, scores,pcvars]=pca(stage265_tran);
>> x265=zscore(scores(:,1));
>> y265=zscore(scores(:,2));
>> z265=zscore(scores(:,3));
>> gscatter3(x265,y265,z265,cellstr(tmp265),{'b','g','m'},{'.','.','.'},15)
If clr is a cell array of strings, the length of clr must be equal to the length of x, y and z.
In my workspace:
stage265_tran <265x100>
scores <265x100>
pcvars <100x1>
x265 <265x1>
y265 <265x1>
z265 <265x1>
tmp265 <1x265>
Answers (1)
Aditya
on 5 Feb 2025
Hi Yue,
The error message you're encountering indicates that the clr parameter in the gscatter3 function expects a cell array of color strings whose length matches the number of data points, not the number of unique groups. This suggests that the function might be expecting a color specification for each individual point, rather than for each group.
Assuming tmp265 correctly specifies groups, and gscatter3 is intended to work similarly to MATLAB's built-in gscatter, you might try:
% Convert tmp265 to a categorical array if it's not already
group = categorical(tmp265);
% Ensure clr is specified for each unique group
uniqueGroups = categories(group);
numGroups = numel(uniqueGroups);
% Define colors for each group
clr = {'b', 'g', 'm'}; % Ensure this matches the number of unique groups
% Define marker types for each group
markerTypes = {'.', '.', '.'}; % Ensure this matches the number of unique groups
% Plot using gscatter3
gscatter3(x265, y265, z265, group, clr(1:numGroups), markerTypes(1:numGroups), 15);
0 Comments
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction 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!