I have matrix and I'd like to plot each line of it with a different linespec:
linespec = {'b.', 'r-', 'g--o','+','x','*','o','.'};h=plot(myMatrix');[row,col]=size(myMatrix); //row can be max. 8for i=1:rowset(h(i),'LineStyle','-','Marker',linespec{i});end
Above code, I get error;
Error using set
Bad property value found.
Object Name: line
Property Name: 'Marker'
Can someone tell me the proper way to accomplish it? Thanks in advance.
Best Answer
As a workaround you can change the Marker Type in the loop as you plot each row, since you can provide a 3rd argument to plot
which specifies the line style,, marker symbol and color:
clcclearM = rand(8);linespec = {'b.', 'r-', 'g--o','+','x','*','o','.'};[row,col]=size(M);hold allfor i=1:rowh(i) =plot(M(i,:),linespec{i});end
Output:
As for the reason behind the error, this page from the MathWorks explains that since R2010a:
You can not set the LineStyle and Marker properties simultaneously.You have to call the SET function twice [...]
So something like this would work:
clcclearM = rand(4);linestyles = {'-', '-.', '--',':'};markers = {'.','>','o','+'};colors = {'b','r','g','k'};h = plot(M)for i = 1:size(M,1)set(h(i), 'LineStyle', linestyles{i})set(h(i), 'Marker', markers{i})set(h(i), 'Color', colors{i})end