You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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:

  1. Use Matlab’s built-in color name (note it’s 'lightblue' without a space):
    yy = plot(Xlink, Ylink, 'color', 'lightblue', 'MarkerSize', 25);
    
  2. 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:

  1. Your plot returned multiple Line objects: If Xlink or Ylink is a matrix, plot() creates one Line object per column, making yy an array of objects. You can’t set the Color property 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
    
  2. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:11:32