Easy MATLAB Graphics: Plot, Change Linewidth and Linestyle

In summary, the conversation is about creating a MATLAB program to plot graphs and make changes to the linewidth and linestyle. The speaker shares that they have successfully created a loop to plot a given function, but are having trouble implementing a feature to change the figureid and linewidth. They also share their code for this specific feature and ask for advice on why it is not working.
  • #1
Kontilera
179
24
Hello! I'm trying to make an easy MATLAB programme in which you can plot your graphs, change the linewidth, and linestyle in the graphs you want etc.
I've managed to use to dialog windows in MATLAB and write a loop which plots a given function. Now I want the programme to ask the user for the figureid and the linewidth and then make the corresponding change.. Here I run into trouble.

My code for this specific m-file is:

Code:
function outt = changewidth(handles)  

Figureid = input('Which figure would you like to change: ');
Width = input('Which width would you like to have: ','s');

z = str2num('Figureid');
p = str2num('Width');


figure(Figureid);
set(z, 'Linewidth', p);

outt=[handles];
end

I don't get any error message but MATLAB won't update the graph that the user refers to..

Any advice?
 
Physics news on Phys.org
  • #2
In my mainfile I just write:

Code:
[...]

case 2 

changewidth(handles)


case 3 
[...]


end
 

1. How do I plot a graph in MATLAB?

To plot a graph in MATLAB, you can use the plot function. This function takes in x and y values as inputs and creates a line plot. For example, plot(x_values, y_values). Make sure to use the hold on command if you want to add multiple lines to the same plot.

2. How do I change the linewidth of a plot in MATLAB?

To change the linewidth of a plot in MATLAB, you can use the linewidth property of the plot function. For example, plot(x_values, y_values, 'linewidth', 2) will create a plot with a linewidth of 2.

3. How do I change the linestyle of a plot in MATLAB?

To change the linestyle of a plot in MATLAB, you can use the linestyle property of the plot function. For example, plot(x_values, y_values, 'linestyle', '--') will create a plot with a dashed line.

4. Can I change the color of my plot in MATLAB?

Yes, you can change the color of your plot in MATLAB by using the color property of the plot function. For example, plot(x_values, y_values, 'color', 'red') will create a plot with a red line.

5. How do I add a title and labels to my plot in MATLAB?

To add a title and labels to your plot in MATLAB, you can use the title, xlabel, and ylabel functions. For example, title('Plot Title'), xlabel('X Axis Label'), and ylabel('Y Axis Label') will add a title and labels to your plot.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
941
Back
Top