MatLab Question Loading and Plotting Data?

7 Ansichten (letzte 30 Tage)
Shalene am 5 Okt. 2014
Practice 3.8, page 97
The sales (in billions) for two separate divisions of ABC Corporation for each of the four quarters of 2013 are stored in a file called "salesfigs.dat"
Cody will randomly generate some data for you, and store it into "salesfigs.dat"
First, create this file (just type the numbers in the Editor, and Save As "salesfigs.dat") Then, write a script that will load the data from the file into a matrix separate this matrix into 2 vectors create the plot seen in figure 3.7 (which uses black circles and stars as the plot symbols).
Enter MATLAB code to
load the data from the file into a matrix separate the matrix into two vectors, DivA and DivB create the plot seen in Figure 3.7 (which uses black circles and black stars as the plot symbols)
function [DivA DivB] = ABCSales(x) %x is a dummy variable and can be ignored; don't use it %Remove the line of code below. Replace it with your code that loads the data, separates it into rows for DivA&DivB, and plots the data as in Figure 3.7 of your textbook
DivA = x;

Antworten (2)

Bruno Pop-Stefanov
Bruno Pop-Stefanov am 6 Okt. 2014
To import data from a file the easiest way is to use the Import Tool. The Import Tool will let you choose the format of the data to import and you can use it to generate a script or a function to repeat the procedure programmatically.
To open the Import Tool, go to the Home tab in the top-left corner of the main MATLAB window and click the "Import Data" button. For more information you can read the documentation here:
I am not sure what kind of plot you would like to create but start by taking a look at the plot function:
The doc page contains examples to get you started.

Brillian Pudya Suci Setianing Ayu
% Baca angka penjualan dari file dan buat plot
load salesfigs.dat
asales = salesfigs(1,:);
bsales = salesfigs(2,:);
hold on
title('ABC Corporation Sales: 2013')
legend('Division A', 'Division B')


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by