Plot outside a for loop with different plotstyles

5 views (last 30 days)
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!

Answers (1)

Ingrid
Ingrid on 9 Jun 2015
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 Comments
Ingrid
Ingrid on 9 Jun 2015
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

Sign in to comment.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!