From: Zachary Roesner on
Hello everyone!
I'm rather new to matlab, as I am a freshmen in an engineering program. That said, I've been working on a script that will plot a set of data and let the user choose the line color, line type, and line point type. In addition, the user can enter the axis names and a title. Below is my script so far. My noob question is: how do i make the color, type, and point type stay together when i use the program? During the script, each replaces the other, leaving the standard blue line behind. Any thoughts? I need help! thanks!!


%These finds the file
filename=input('Enter file name: ','s')
data = load (filename)

[rows, cols] = size(data); %find out the number of rows and columns

datatype= menu('Are your coordinates in row or column format?: ','row','column')
if 'row'
x= data(:,1)
y= data(:,2)

end

if 'column'
x= data(:,1)
y= data(:,2)

end

% This allows the user to select the color of the data points

datacolor=menu('What color do you want to use','y','m','c','r','g','b','w','k')

switch datacolor
case 1
plot(x,y,'y')
case 2
plot(x,y,'m')
case 3
plot(x,y,'c')
case 4
plot(x,y,'r')
case 5
plot(x,y,'g')
case 6
plot(x,y,'b')
case 7
plot(x,y,'w')
otherwise
plot(x,y,'k')
end

%This allows the user to select the type of line

datalinetype=menu('What type of line do you want to use','-',':','-.','--')

switch datalinetype
case 1
plot(x,y,'-')
case 2
plot(x,y,':')
case 3
plot(x,y,'-.')
otherwise
plot(x,y,'--')
end

%This allows the user to select the type of data point

datapointtype=menu('What type of point would you like to use','.','o','x','+','*','s','d','v','^','>','<','p','h')

switch datapointtype
case 1
plot(x,y,'.')
case 2
plot(x,y,'o')
case 3
plot(x,y,'x')
case 4
plot(x,y,'+')
case 5
plot(x,y,'*')
case 6
plot(x,y,'s')
case 7
plot(x,y,'d')
case 8
plot(x,y,'v')
case 9
plot(x,y,'^')
case 10
plot(x,y,'>')
case 11
plot(x,y,'<')
case 12
plot(x,y,'p')
otherwise
plot(x,y,'h')
end

%Add labels, title,and text to plot

%Add a label on the x axis
xlabeldata = input('Enter the x axis title: ','s')
xlabel(xlabeldata)

%Add a label on the y axis
ylabeldata = input('Enter the y axis title: ','s')
ylabel(ylabeldata)

%Add a title to the top of the plot
titledata = input('Enter a title name: ','s')
title(titledata)
From: Matt Fig on
See, for example:

http://www.mathworks.com/matlabcentral/fileexchange/9522-ezgraph
From: Zachary Roesner on
Your attached file helps a small bit,

but I'm really interested in how i can get the line color, line type, and point type to all appear on the graph, not just one of the three like my script does.

Please help!!

Thank you!
From: TideMan on
On Feb 8, 5:17 am, "Zachary Roesner" <z...(a)pitt.edu> wrote:
> Your attached file helps a small bit,
>
> but I'm really interested in how i can get the line color, line type, and point type to all appear on the graph, not just one of the three like my script does.
>
> Please help!!
>
> Thank you!

Before plotting, you need to assemble all the information, then plot
using that information.
So, you should have one and only one plot command.

Also, I noticed that you have screwed up the row/column bit.
Actually, you don't need to ask such a damn fool question, but let
Matlab figure it out.
if rows > cols
x=data(:,1);y=data(:,2);
else
you work it out
end
From: Rune Allnor on
On 6 Feb, 23:00, "Zachary Roesner" <z...(a)pitt.edu> wrote:
> Hello everyone!
> I'm rather new to matlab, as I am a freshmen in an engineering program.  That said, I've been working on a script that will plot a set of data and let the user choose the line color, line type, and line point type.  In addition, the user can enter the axis names and a title.  Below is my script so far.

This is certainly good exercise in handling graphics trhough
code (as opposed th through the GUI), but this kind of script
would not work as a plotting tool.

Plotting tasks are just too diverese that one can reasonably
get "one script to rule them all", to paraphrase J.R.R.Tolkien.

> My noob question is: how do i make the color, type, and point type stay together when i use the program? During the script, each replaces the other, leaving the standard blue line behind.

Print a *hard* *copy* of the matlab graphics guide, and browse.
There are plenty of ways you can modify and manipulate plots
through code, and the graphics guide is the place to start.

Once you get through the basics, make sure you make your plots
through scripts instead of GUI manipulations. That way you can
reproduce figures years after you first made them (as long as
you also have whatever data they were based on available), and
you can quickly modify and adjust figures for special purposes.
The newbie might think plotting via scripts is a hazzle, but in
reality it's one of *the* most powerful aspects of matlab.

Well worth exploring.

Rune