Data Visualization Using MATLAB


MATLAB:- (MATrix LABoratory) is a superior language for specialized figuring developed by MathWorks. It coordinates calculation, perception, and programming in a simple way to utilize conditions where issues and arrangements are communicated in familiar mathematical notation.

Regular uses include:  

      ·        Math & Calculation improvement,
            ·        Modeling, simulation, and prototyping,
            ·        Data analysis, exploration and visualization and
            ·        Generate Highly customized reports and report programs.
            ·        Application improvement including Graphical User Interface building.

            This is a high-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features. It allows to create quick and throw away programs and also create Complex programs. While other programming languages work with numbers each in turn, MATLAB is intended to work fundamentally on Matrices and arrays.
      
         All MATLAB variables are multidimensional arrays, no matter what type of data. A matrix is a two-dimensional array often used for linear algebra.
    Data visualization:-
     In MATLAB, We can create 2-D (having two axis points) and 3-D (having three-axis points) plots. For creating these plots/visualize data we should have an editor. 

                                                        Fig 1:- MATLAB Home
By using MAXL commands & functions, we can create visualizations as required.
On the Home tab, New live script icon is available. Click on that to display a new script which will come under the Live Editor tab.


Fig 2:- Live Editor section
    You can view and explore data using interactive visualizations such as an area plot, line plot, or scatter plot in static visualizations using other MATLAB plots. Here we can plot different kinds of plots to visualize data. Some of the kinds are:-

           1.     Bar plot,
           2.     Pie plot,
           3.    Area plot,
           4.    Polar plot,
           5.    Scatter plot,
           6.    Stem plot etc..,

Sample Program to create Bar graph:-

Program:-
Clear all;
Close all;
Costs= [38556 24472 14556 18060 19549 8122 28541 7880 3283 4135 7953 1884];
Sales = [20178 23536 34561 37395 36072 32237 18597 9408 6005 6268 8963 13882];
bar(1:12, [Costs' Sales'], 1)
axis([0 13 0 40000])                          --> represents Scale of division for x,y axis 
title('Netsales by month')
xlabel('Month')
ylabel('Sales')    
legend('Costs', 'Sales')
Click on run button and will be redirected to Figure tab, where you can see what's the exact figure looks like.
                                                                   Fig 3:- BAR Graph
For saving the plot,
Print(‘plot’, ‘-dpdf’, ‘-r200’)
--> dpdf refers Format for saving the plot.
--> r200 refers resolution of image.          
                                              (or)
  We can save the script by clicking on "Save As" command with required name and extension.
Some of the extensions listed below:-
                                                                                                             Fig 4:- Types of Extensions
To add titles and labels to the plots,
Title(‘based on the dataset’)
Label(‘Parameters of X-axis’)
Label(‘Parameters of Y-axis’)
we can enable grids for the plot using the option available in MATLAB (or) by using the command in the Editor section and also can add a legend (descriptions) into the plot.

Also, we can compare two data sets by Overlaying bar graphs on each other.
Example:-
Clear all;
Close all;
x = [1 2 3 4 5];                                                   --> X-axis representations
temp_high = [32 35 39 44 48];                          --> Y-axis representation of 1st data set 
w1 = 0.5;                                                            --> Width of 1st bar
bar(x,temp_high,w1,'FaceColor',[0.7 0.2 0.5])  --> Figure type and colour representation
temp_low = [22 24 32 36 43];                            --> Y-axis representation of 2nd data set
w2 = .25;                                                             --> Width of 2nd bar
hold on                                                                --> Represents overlaying of plots
bar(x,temp_low,w2,'FaceColor',[0 0.7 0.7])       --> Figure type and colour representation
ylabel('Temperature (\circC)')                             --> Notation for Y- axis
legend({'Average High','Average Low'},'Location','northwest') 
grid on 
                 Fig 5 :- Overlaying Bar Graph
In view to the above Overlaying bar graph representation, can also mention “Area” figure type as per the requirement.
By adding below arguments and setting up properties, we can change the text of X-axis.
Ax = gca;
ax.Xtick = [1 2 3 4 5]; 
XtickLabels = {‘January’,’February’,’March’,’April’,’May’};
XtickLabelRotation = 45;
Fig 6:- Overlay Bar Graph with Ticklabels and Ticklabel rotation functions
Also, we can represent the Bar graph on top of one another like a stack using the above example. For this, we use a STACKED command.
è bar(Costs, "Stacked")
                                                                                   Fig 7:- 2D Stacked Bar Graph
In addition to that, we can also plot 3D plots in MATLAB. 
The bar3 function draws each element as a separate 3-D block and distributes the elements of each column along the y-axis. 3 axis points are determined in the matrix to plot a 3Dimensional plot.
Example:- Costs= [38556, 24472, 14556
                               18060, 19549, 8122
                                28541, 7880, 3283
                                4135, 7953, 1884];
                         b = bar3(Costs);

Fig 8:- 3D Bar Graph
Next will Plot different colors to the above graph according to the height of bars.
Fig 9:- 3D Graph with Colour differentiation according to height
In the above example, mentioned costs data set. In reference to that, we can use the “MAGIC” function to build n -by- n matrix constructed from the integers 1 through n^2 with equal row and column sums.
Syntax:- MAGIC (n)    à N represents natural number.
The errorbar function draws a line plot of x and y values and superimposes a vertical the error bar on each observation.
In addition to those, we can also plot Stem plots, scatter plots and Polar plots in MATLAB. 

Stem Plot:- The stem function draws a marker for each x and y value with a vertical line connected to a common baseline.
Fig 10:- Stem Plot

Polar Plots:- The polar plot function draws a polar plot of the angle values in theta (in radians) versus the radius values in rho.
Fig 11:- Polar plots
The below example describes, how to combine a line chart and a bar chart using two different y-axes. The plot chart has two y-axes using the yy-axis. Bar chart using the left y-axis and line chart using the right y-axis.
Fig 12:- Combined Line and Bar Graph
Pie chart:- Pie(X) draws a pie chart using the data in X. Each slice of the pie chart represents an element in X.

Procedure for creating Offset Pie slice for different products:-
1. Set up a three-column array, X, so that each column contains yearly sales data for a specific product over a 5-year period.
2. Calculate the total sales for each product over the 5-year period by taking the sum of each column. Store the results in product_totals.
3. Use the max function to find the largest element in product_totals and return the index of this element, ind.
4. Use the pie function input argument, explode, to offset a pie slice. The explode argument is a vector of zero and nonzero values where the nonzero values indicate the slices to offset. Initialize explode as a three-element vector of zeros.
5. Use the index of the maximum element in product_totals to set the corresponding to explode element to 1.
6. Then create a Pie chart of total sales for each product and offset the pie slice for the product with the largest total sales. Below is the figure of the pie slice. 

Fig 13:- Pie Chart
In addition to the above plots, MATLAB also supports to create geographic plots used to plot specific geographic locations data and its variances. It can also create animations (Line animations, Object animations and surface animations) for the available data.


The built-in functions provide efficient usage and offer different approaches to visualizing data.
















                                                           
                                                                                            













Comments

  1. If you're attempting to lose pounds then you absolutely need to try this totally brand new personalized keto diet.

    To create this keto diet service, certified nutritionists, fitness couches, and chefs joined together to provide keto meal plans that are efficient, decent, price-efficient, and delicious.

    Since their grand opening in January 2019, thousands of individuals have already completely transformed their figure and well-being with the benefits a good keto diet can provide.

    Speaking of benefits; in this link, you'll discover 8 scientifically-confirmed ones offered by the keto diet.

    ReplyDelete
  2. Great presentation with such infographic informed in detailed, please must write relevant content for us in future.

    ReplyDelete
  3. Excellent article for the people who need information about this course.
    Learn Data Science Online

    ReplyDelete
  4. This post is so helpfull and attractive.keep updating with more information...
    Data Science Positions
    Courses On Data Science

    ReplyDelete
  5. This site have particular software articles which emits an impression of being a significant and significant for you individual, able software installation.This is the spot you can get helps for any software installation, usage and cracked.
    matlab-crack

    ReplyDelete

Post a Comment

Popular posts from this blog

Differences between Ignore (~) vs Never(^) consolidation properties

MAP REPORTING APPLICATION IN HYPERION PLANNING