Plotting Multiple Pictures with Points from a Matrix in MATLAB

In summary, you need to load the file with the -ascii flag and use "plot" to create plots. Then you can set the position of the axes.
  • #1
maxmilian
12
0
Hi all

I am novice MATLAB programmer, and I need alittle help with plotting points, given in a txt. file.

I have a text file containing 56 points for 40 pictures. I've loaded the txt file by "load -ASCII nameofthefile.TXT" - and thereby created a matrix <112x40 double> the first 56 rows are x and rows from 57 to 112 are the y. My question is how do I plot each of these 40 pictures each containing the 56 points ?

kind regards

Maxmilian
 
Physics news on Phys.org
  • #2
for i=1:40
plot(A(1:56,i),A(57:112,i))
pause(.1)
end
 
  • #3
Thanks for your nice reply - what would I need to do if I wanted to have multiple plots in the same figure ?
 
  • #4
doc subplot

OR (better)

Download subaxis from the file exchange and play with it and read the help file and documentation
 
  • #5
subplot is unfortunately not what I need. I need the plots to overlap each other
 
  • #6
You'll have to call the axes by handle then:

ax.(sprintf('%i',i)) = axes;

Thn you can set their position manually:

set(ax(sprintf('%i',i),'Position',rect);

Where rect is a four element vector of the four corners. Try googlIng "axes properties"
 
  • #7
I resolved it by using "hold on"
But I am getting a error with my function when I am trying this ;

function figureplot(m)
load -ascii shapes.txt

for i=1:m
...

? Input argument "m" is undefined.

What I am trying to do, is making a function where I can tell it how many plots I want in a single figure. So by calling figureplot(5) - it would plot 5 plots in a figure.
 
  • #8
Oh! you wanted them to overlap all in the same place...? Why don't you just plot them all at once?

I don't see a problem with what you've posted. I usually don't use the -ascii flag and haven't had problems, but maybe it's something you do elsewhere in your code?
 

1. How do I plot a matrix in Matlab?

To plot a matrix in Matlab, you can use the plot function. Simply pass in the matrix as an argument, and Matlab will automatically plot each column as a separate line on the graph.

2. Can I customize the appearance of the plot?

Yes, you can customize the appearance of the plot by using additional arguments in the plot function. For example, you can specify the color, line style, and markers for each line. You can also add a title, labels for the x and y axes, and a legend to the plot.

3. How can I plot only specific columns of a matrix?

To plot only specific columns of a matrix, you can use indexing. For example, if you have a matrix called A and you only want to plot the first and third columns, you can use plot(A(:,[1 3])). This will plot the first and third columns as separate lines on the graph.

4. What if I want to plot multiple matrices on the same graph?

If you want to plot multiple matrices on the same graph, you can use the hold on command. This will allow you to plot multiple lines on the same graph without overwriting the previous ones. Just make sure to use hold off when you are finished plotting to reset the graph for the next plot.

5. Is it possible to save the plot as an image or PDF?

Yes, you can save the plot as an image or PDF by using the saveas function. Simply pass in the name of the file and the desired file format as arguments. For example, saveas(gcf, 'myplot.png') will save the current plot as a PNG image in your current working directory.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top