Plot outside a for loop with different plotstyles
1 次查看(过去 30 天)
显示 更早的评论
Hello all,
I've got a vector a with 20 values and a for loop, through which I want to plot the variables var1 and b
%%%%%%
%Define the variables
a = 1:20;
b = 0:0.01:1;
n= numel(a);
m=numel(b);
var1 = zeros(n,m);
***********************
%% For loop
for i = 1:n
var1(i,:)=(2+b).^(a(i));
end
****************************
At the end, var is a matrix sized: 20 x 101 and b is a vector 1 x 101.
When I am plotting
figure
plot(b,var1)
%%%%%%%%%%%%%%%%%%%%
I've got a figure with 20 lines, however, these are specified by default. I need to define the colours and the plot styles for every single of those lines
For example, I want the 1st line to be --> b-,
the 2nd--> r-
the 3rd--> m-
the ..... 15th --> b.
and so on...
Any thoughts on that ?
Many thanks!
0 个评论
回答(1 个)
Ingrid
2015-6-9
doc plot
will learn you this:
h = plot(_) returns a column vector of lineseries handles, where h contains one handle per line plotted. When multiple lines are present, you can make changes to properties of a specific line by specifying its handle.
so use this handle in combination with set There is even a complete example worked out showing to do what you want (Change Line Properties Using Handles) but you can also automize this in a for loop when you store your colors and linestyles in a matrix
2 个评论
Ingrid
2015-6-9
try
plot(b,var1(:,i),plotStyle{i})
inside the for loop
you need to index your var1 variable because now you are just plotting all 20 lines with the same linestyles 20 times, hence only showing the last style as this one is on top.
If you would open the editor you would see this behaviour
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!