Matlab大型图表RGB颜色与透明度设置报错问题咨询
Let's break down your two errors and fix them step by step:
First Error: Undefined rgb function
Matlab doesn’t have a built-in rgb() function—you might be mixing it up with libraries from other languages (like Python’s matplotlib) or forgot to define a custom function with that name.
To set a light blue color, you have two straightforward alternatives:
- Use Matlab’s built-in color name (note it’s
'lightblue'without a space):yy = plot(Xlink, Ylink, 'color', 'lightblue', 'MarkerSize', 25); - Use a normalized RGB value (all values between 0 and 1; light blue is roughly
[0.67 0.84 0.90]—adjust as needed):yy = plot(Xlink, Ylink, 'color', [0.67 0.84 0.90], 'MarkerSize', 25);
Second Error: Issues with setting yy.Color
The "Undefined function or variable" error here is likely one of two scenarios:
- Your plot returned multiple Line objects: If
XlinkorYlinkis a matrix,plot()creates one Line object per column, makingyyan array of objects. You can’t set theColorproperty on the entire array directly—loop through each object instead:yy = plot(Xlink, Ylink, 'MarkerSize', 25); % Check if yy is an array of Line objects if ~isscalar(yy) for i = 1:length(yy) yy(i).Color = [1 1 1]; % Equivalent to [255 255 255]/255 (white) end else yy.Color = [1 1 1]; end - Outdated Matlab version: Very old Matlab versions use different syntax for setting line properties. If that’s the case, use the
set()function instead:yy = plot(Xlink, Ylink, 'MarkerSize', 25); set(yy, 'Color', [1 1 1]);
A quick note: Matlab requires color values to be normalized between 0 and 1, so your [255 255 255]./255 is correct—but you can also just write [1 1 1] for simplicity.
内容的提问来源于stack exchange,提问作者StarGit
相关产品推荐
相关产品推荐

