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:
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.
I am completely new in Matlab...
Thanks in advance
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
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
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
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.