Using a custom color array. "Color value must be a 3 element vector".

I have a GUI with various graphs. Here is a function that plots values onto one of the graphs. The function below works if colVal = ['r', 'y', 'k'....etc.], but once I try to use raw color values, I receive the error "Color value must be a 3 element vector. As far as I can tell, each cell contains 3 elements. What am I doing wrong? Any help is appreciated.
function L1_lineDisplay(radioStatus, handles)
% radioStatus - a 12x1 binary vector indicating which electrode pairs are
% selected and which are not
% handles - handle obj from the gui
ind1 = find(radioStatus(1:6) == 1);
colVal = {[0 0.4470 0.7410],...
[0.8500 0.3250 0.0980],...
[0.9290 0.6940 0.1250],...
[0.4940 0.1840 0.5560],...
[0.4660 0.6740 0.1880],...
[0.3010 0.7450 0.9330]}
% Prepare the x and y lines for each electrode pair
xlines = handles.xlines;
ylines = handles.ylines;
% Plot the lines for the active electrodes
set(gcf,'CurrentAxes', handles.lead1_ax);
set(gcf,'Renderer','painters');
for i = 1:length(ind1)
line(xlines(:,ind1(i)), ylines(:,ind1(i)), 'Color', colVal(ind1(i)),'linewidth', 3); hold on;
end
end

 采纳的回答

Try
colVal{ind1(i)}
instead. That will be the contents of the cell, which is the 1x3 array you intended (rather than the cell itself).

3 个评论

() pull the entire drawer out of the chest of drawers (cell array), {} pull out the socks.
I'm trying to set a custom color array for categorical data using the function gscatter. when I try to set the "MarkerFaceColor" i get the same error message @ was getting, even though my "colors" variable is actually a 8x3 array.
I have tried @thecyclist answer, but it does not seem to work in my case. This is the nearest solution I could figure: After running this code, I obtain a plot with the colors I'have assigned on the array, but applied only to the edge of the marker.
What should I do?
e.g.:
figure
color =[0.4660, 0.6740, 0.1880;...
0.6350, 0.0780, 0.1840;...
0, 0.4470, 0.7410;...
0.3010, 0.7450, 0.9330;...
0.75, 0.75, 0;...
0.9290, 0.6940, 0.1250;...
0.8500, 0.3250, 0.0980;...
1, 0, 0]
h = gscatter(X, Y, g, color,'s', 10);
for n = 1:length(h)
set(h(n), 'MarkerFaceColor', color(n));
end
You need
set(h(n), 'MarkerFaceColor', color(n,:));
to get each row of your color array, instead of the nth element.
FYI, in the future you might want to post a new question, and include a link to the related older one. Typically, people will not see comments on very old questions. (I just happened to see this by luck.)

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Geographic Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by