Using a custom color array. "Color value must be a 3 element vector".
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
the cyclist
il 8 Lug 2015
Modificato: the cyclist
il 8 Lug 2015
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 Commenti
Amanda
il 15 Dic 2020
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
the cyclist
il 23 Dic 2020
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.)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating, Deleting, and Querying Graphics Objects in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!