我想在MATLAB中用不同的颜色保存多个圆形的png文件。我希望有一个名为多个文件:用matlab命名一个带有函数后缀的文件
RINGS_Base_<n><colorname>
n
显示不同的文件的数量和colorname
是圆的颜色的名称。
由于圆圈有RGB颜色,我使用函数translatecolor将每个RGB颜色转换为颜色的实际名称。
当我命名每个文件时,我可以调用该函数吗?如果不是,我怎样才能用各自的颜色命名所有文件?
非常感谢您的帮助。
这里是我的代码:
RGB = [1 1 0; 1 0 1; 0 1 1; 1 0 0; 0 1 0; 0 0 1];
%
%RIGNSGenerator_FilledCircle1
%
n=1;
for col1 = transpose(RGB)
FilledCircle1(2,2,5,300,transpose(col1)) %function []=FilledCircle1(x0,y0,Radius,N,col1)
print (strcat ('/Users/Stimuli_Rings/RINGS_Circle_', num2str(n),translatecolor(col1), '.png'), '-dpng') %strcat is to combining strings together
n=n+1;
end
function out=translatecolor(in) % translates the RGB colour into the actual name of the color
switch(in)
case [1 1 0], out='yellow';
case [1 0 1], out='pink';
case [0 1 1], out='cyan';
case [1 0 0], out='red';
case [0 1 0], out='green';
case [0 0 1], out='blue';
return;
end
end
嗯......是吗?这里是否存在实际问题?它看起来像你已经在做的事情(至少大部分)是正确的... – tmpearce
我有以下错误,我无法理解@tmpearce:>> RIGNSGenerator SWITCH表达式必须是标量或字符向量常量。 错误RIGNSGenerator> translatecolor(第18行) 开关(上) 错误RIGNSGenerator(第12行) 打印(strcat的( '/用户/ Stimuli_Rings/RINGS_Circle_',num2str(N),translatecolor(COL1),' '),'-dpng') %strcat是将字符串组合在一起 – Mraquel