Thread Subject:
Read data from files using textscan & plot histogram/ecdf using plotyy

Subject: Read data from files using textscan & plot histogram/ecdf using plotyy

From: BP

Date: 22 Jun, 2012 08:22:07

Message: 1 of 2

I try to read a text files with 20x20 data into variable C, and attempt to plot a histogram on the left Y-axes, and a ecdf/ksdensity on the right X-axes.

Using textscan, the data is read into a 400x1 array. However, when I tried to call plotyy to plot histogram, the code belows return

-------------------------------------------
Error using plot
Vectors must be the same lengths.

Error in pt (line 11)
axes = plotyy(x,C{1},x,C{1});
-------------------------------------------

I guess it is due to C{1}. But have no clue on how to resolve it. I am new to matlab, would anyone point out the correct way to perform the above operations?

-------------------------------------------
fid = fopen('t1_error.txt','r');
C = textscan(fid, '%.3f');
fclose(fid);

disp(C{1});

x = -1:7;
axes = plotyy(x,C{1},x,C{1});
hold on
hist(axes(1), C{1}, x);
ylim(axes(1),'auto');
set(axes(1),'mode','auto');
hold off
-------------------------------------------

Subject: Read data from files using textscan & plot histogram/ecdf using plotyy

From: Steven_Lord

Date: 22 Jun, 2012 13:27:25

Message: 2 of 2



"BP " <syseeker@yahoo.com> wrote in message
news:js19ve$1ag$1@newscl01ah.mathworks.com...
> I try to read a text files with 20x20 data into variable C, and attempt to
> plot a histogram on the left Y-axes, and a ecdf/ksdensity on the right
> X-axes.
>
> Using textscan, the data is read into a 400x1 array. However, when I tried
> to call plotyy to plot histogram, the code belows return
>
> -------------------------------------------
> Error using plot
> Vectors must be the same lengths.
> Error in pt (line 11)
> axes = plotyy(x,C{1},x,C{1});

You're plotting the same x and y twice in a call to PLOTYY? That seems
unnecessary.

> -------------------------------------------
>
> I guess it is due to C{1}. But have no clue on how to resolve it. I am new
> to matlab, would anyone point out the correct way to perform the above
> operations?

Just before that line in your code, look at:

size(x)
size(C{1})

Those two commands will return different vectors and that is the cause of
the problem. If x and C{1} aren't the same size, how do you expect to be
able to plot them?

You may need to tweak the code that creates x; some functions that may be of
use to you are SIZE, LENGTH, or NUMEL.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
plotyy BP 22 Jun, 2012 04:24:08
textscan BP 22 Jun, 2012 04:24:08
rssFeed for this Thread

Contact us