matlab c(i,j)=i+j; i=1:100,j=1:100,要在100*100的平面上用不同颜色表示c(i,j)值的不同,颜色平滑过渡
答案:1 悬赏:30 手机版
解决时间 2021-03-07 02:09
- 提问者网友:王者佥
- 2021-03-06 22:46
matlab c(i,j)=i+j; i=1:100,j=1:100,要在100*100的平面上用不同颜色表示c(i,j)值的不同,颜色平滑过渡
最佳答案
- 五星知识达人网友:長槍戰八方
- 2021-03-07 00:15
In order to customize color order in the plot, I recommond you to use command:
>> jet( n ) % n is the total number of your plotsAs you should know, the color is representative by a three-element row vector, which is the RGB value.
For example:
RGB color
[0 0 0] | black
[1 1 0] | yellow
The automatically colorful plot is therefore all about the change of the RGB value by applying [ jet( ) ] command in Matlab.
Here is a simple example code to help you better understand the implication of this command in plot.
n = 10; % number
c = jet(n); % color
x = 0:.01:1;
for i = 1:n
y = x.^(1+i);
plot(x,y,'color',c(i,:)); % the key to obtian
% colorful plot effect!!!
hold on
end
hold offFor your question, the code could be written as:
clear all
n = 100;
[a,b] = meshgrid(1:n);
c = a + b;
cc = jet(n*n);
v = 0;
for i = 1:n
for j = 1:n
v = v + 1;
plot3(a(i,j),b(i,j),c(i,j),'o','color',cc(v,:))
hold on
end
end
hold offThe graphic will be displayed as
However, in my opinion your question doesn't require any excessive command to achieve your request at all.
Here is the modified code to achieve what you expect but yet facter than the previous one.
clear all
n = 100;
[a,b] = meshgrid(1:n);
c = a + b;
mesh(a,b,c)
Chance is yours!!! Cheers...
>> jet( n ) % n is the total number of your plotsAs you should know, the color is representative by a three-element row vector, which is the RGB value.
For example:
RGB color
[0 0 0] | black
[1 1 0] | yellow
The automatically colorful plot is therefore all about the change of the RGB value by applying [ jet( ) ] command in Matlab.
Here is a simple example code to help you better understand the implication of this command in plot.
n = 10; % number
c = jet(n); % color
x = 0:.01:1;
for i = 1:n
y = x.^(1+i);
plot(x,y,'color',c(i,:)); % the key to obtian
% colorful plot effect!!!
hold on
end
hold offFor your question, the code could be written as:
clear all
n = 100;
[a,b] = meshgrid(1:n);
c = a + b;
cc = jet(n*n);
v = 0;
for i = 1:n
for j = 1:n
v = v + 1;
plot3(a(i,j),b(i,j),c(i,j),'o','color',cc(v,:))
hold on
end
end
hold offThe graphic will be displayed as
However, in my opinion your question doesn't require any excessive command to achieve your request at all.
Here is the modified code to achieve what you expect but yet facter than the previous one.
clear all
n = 100;
[a,b] = meshgrid(1:n);
c = a + b;
mesh(a,b,c)
Chance is yours!!! Cheers...
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯