Solved

# How to plot graph of financial data with matlab?

Posted on 2010-01-08
1,018 Views
Hi,
I am new with Matlab and need some help:
I have financial data that I can produce from another application to a text file.
the  text file structure will be like: (I can change it)

1,1.4524
2,1.4520
3,1.4530
4,1.4520
5,0
6,0
7,0
.
.

The left column (1,2,3,4,..) represents the time in minutes.
The right collumn represents the values that I want to see in the Y axis.

I iuse the File->Import Data to import  the data text file into Matlab.

1) How to write the command for plotting the graph?
2) In case that I want to have a graph of 10 min intervals instead of 1 minute intervals, how to do it from Matlab?

3) When there is no data (e.g. weekend) the right column gets value 0, What is the recommended solution for showing 0 data on the graph(but only as indicator, not spending too much graph space)?
4) How to scale the Y axis to show the correct values? (In this example from 0.9 to 2)
Thanks!
0
Question by:star90

LVL 15

Accepted Solution

See the code below with comments (after %). In case of missing data you can write NaN (not-a-number) to the data file. Or convert 0s to NaN. There will be a gap on the plot.
``````%% Read the data from comma-delimited file

%% Convert 0s to NaNs

data(data(:,2)==0,2)=NaN;

%% plot 2nd column vs. 1st

plot(data(:,1),data(:,2))

%% plot symbols without lines (see PLOT help for details)

plot(data(:,1),data(:,2),'r*')

%% plot with 10 min interval

plot(data(1:10:end,1),data(1:10:end,2))

%% Scale the Y axis

ylim([0.9 2])
``````
0

Author Comment

Thanks a lot.
Its working well !
0

## Featured Post

### Suggested Solutions

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Whether youâ€™re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.