0

How do I import a matrix into Matlab and then visualize it as a surface?

I want to have it something like this at the end:

http://www.mathworks.se/help/matlab/ref/meshgrid.html

to be able to do that I have to first have it as an input of the meshgrid(according to the file) but I have no idea how to do that.

enter link description here

I am completely new in Matlab...

Thanks in advance

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
a a
  • 35
  • 7

1 Answers1

1

The are many possibilities (file formats, visualisation functions, etc) depending on what you would like to achieve. The simplest example I can think of is as follows.

Suppose you have a file named data.txt in your working directory that contains

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

17 18 19 20

Then the commands

M = load('data.txt');
surf(M)
xlabel('x')
ylabel('y')
title('Matrix M')

will give you the following plot

Matrix visualisation

Since the matrix M is not a square matrix, you can see in the plot which dimension is assigned to each axis.


To change the viewpoint you can use the view command. All there is to this command is summarised in this picture

enter image description here

taken from here http://www.mathworks.com/help/matlab/visualize/setting-the-viewpoint-with-azimuth-and-elevation.html

The first argument to be passed to the view command is the azimuth and the second argument is the elevation, as defined in the picture above.

For example, if you want to make the order of the values on the x and y axes appear reversed, you can first read the current azimuth and elevation

% get from current axes the attribute View
current_view = get(gca,'View');

and change it with view(current_view + [180 0]). The result is

enter image description here

You can also rotate a plot interactively: on the toolbar of the Figure window there is a circular arrow. You can click on it to activate it and then click and drag inside the window.

Drake
  • 857
  • 5
  • 10
  • thanks a lot...I have one more question. How do you use the "View" to be able to look at the visualized data from different sides?(I added the link into the post) – a a Mar 30 '14 at 04:59
  • Please have a look at the section I added to the answer. – Drake Mar 30 '14 at 12:23