using matlab for visualization / surface

by a a   Last Updated October 21, 2018 10:26 AM

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.

enter link description here

I am completely new in Matlab...

Thanks in advance

Answers 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');
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

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.

March 29, 2014 21:51 PM

Related Questions

How to make a matrix for a particular surface plot?

Updated November 04, 2017 02:26 AM

Matlab - Layers of individual plots

Updated August 21, 2017 16:26 PM