Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Connecting the dots between data points

Subject: Connecting the dots between data points

From: Philosophaie

Date: 23 Oct, 2010 19:11:06

Message: 1 of 8

I have an array. It contains the dates (month, day and year) of when the TAI in France subtracted a second to the UTC to correct for the slowing of the revolution of the Earth. I can graph this array. I first covert the date to Julian Date then plot:

plot(JD(k),TAIminusUTC(k))

I tried:

plot(JD(k),TAIminusUTC(k),-b)

but it gave me an error.
-----------------------------------------------------------
??? Undefined function or variable 'b'.

Error in ==> TimeScales>GraphSheet1 at 28
        plot(JD(k),TAIminusUTC(k),-b)

??? Error while evaluating uicontrol Callback.
--------------------------------------------------------------

Subject: Connecting the dots between data points

From: Philosophaie

Date: 23 Oct, 2010 19:49:04

Message: 2 of 8

I would also like to plot and use "Tools>Basic Fitting" between just the dates entered in the array.

Subject: Connecting the dots between data points

From: Philosophaie

Date: 23 Oct, 2010 20:32:06

Message: 3 of 8

The problem is there is no unique x->y relationship in my data. There are many xs for the same y. I tried this:

if TAIminusUTC(k)~=TAIminusUTC(k-1)
       plot(JD(k),TAIminusUTC(k))
end
hold on;

but it still will not connect the dots. It just draws the dots no lines.

Subject: Connecting the dots between data points

From: Jan Simon

Date: 23 Oct, 2010 21:34:05

Message: 4 of 8

Dear Philosophaie,

> if TAIminusUTC(k)~=TAIminusUTC(k-1)
> plot(JD(k),TAIminusUTC(k))
> end
> hold on;
>
> but it still will not connect the dots. It just draws the dots no lines.

Of course. You command Matlab to draw single dots. If you want to draw a line, PLOT needs vectors as inputs.
You can find the indices where TAIminusUTC changes with the DIFF command, perhaps with:
  index = [1, diff(TAImunusUTC) ~= 0];
  plot(JD(index), TAImunusUTC(index));

Jan

Subject: Connecting the dots between data points

From: Philosophaie

Date: 23 Oct, 2010 22:23:05

Message: 5 of 8

What is a simple way to make a vector out of an array, taiutc(n), without the diff command. (the below prints just dots)

for k=2:76
    JD(k)=367 * A(k,3) - floor(7 * (A(k,3) + floor((A(k,1) + 9) / 12)) / 4) + floor(275 * A(k,1) / 9) + A(k,2) + 1721013.5
    TAIminusUTC(k)=A(k,4)
     if TAIminusUTC(k)~=TAIminusUTC(k-1)
       n=n+1
       mjd(n)=JD(k)-2400000.5
       taiutc(n)=TAIminusUTC(k)
       plot(mjd(n),taiutc(n))
    end
end

> Of course. You command Matlab to draw single dots. If you want to draw a line, PLOT needs vectors as inputs.
> You can find the indices where TAIminusUTC changes with the DIFF command, perhaps with:
> index = [1, diff(TAImunusUTC) ~= 0];
> plot(JD(index), TAImunusUTC(index));

Subject: Connecting the dots between data points

From: Jan Simon

Date: 23 Oct, 2010 22:45:07

Message: 6 of 8

Dear Philosophaie,

> What is a simple way to make a vector out of an array, taiutc(n), without the diff command. (the below prints just dots)

I do not see a connection between these two sentences. Is there any?
DIFF does not create a vector out of an array. It calculates the difference between neighboring elements.
I offered a solution *with* the DIFF command. Does it work for you or not? What is the reason to avoid DIFF?

Jan

Subject: Connecting the dots between data points

From: Jan Simon

Date: 23 Oct, 2010 22:49:05

Message: 7 of 8

Dear Philosophaie,

 n = 0;
 mjd = zeros(1, 76); % Ever preallocate!!!
 taiutc = zeros(1, 76); % Ever preallocate!!!
 for k=2:76
     JD(k)=367 * A(k,3) - floor(7 * (A(k,3) + floor((A(k,1) + 9) / 12)) / 4) + floor(275 * A(k,1) / 9) + A(k,2) + 1721013.5
     TAIminusUTC(k)=A(k,4);
      if TAIminusUTC(k)~=TAIminusUTC(k-1)
        n = n+1;
        mjd(n) = JD(k)-2400000.5;
        taiutc(n)=TAIminusUTC(k);
        % plot(mjd(n),taiutc(n)) % Not here for points
     end
 end
 plot(mjd(1:n), taiutc(1:n)); % But here for a vector

Jan

Subject: Connecting the dots between data points

From: Steven_Lord

Date: 24 Oct, 2010 02:53:48

Message: 8 of 8



"Philosophaie" <ertlejack@sbcglobal.net> wrote in message
news:i9vc0a$5q7$1@fred.mathworks.com...
> I have an array. It contains the dates (month, day and year) of when the
> TAI in France subtracted a second to the UTC to correct for the slowing of
> the revolution of the Earth. I can graph this array. I first covert the
> date to Julian Date then plot:
>
> plot(JD(k),TAIminusUTC(k))
>
> I tried:
>
> plot(JD(k),TAIminusUTC(k),-b)
>
> but it gave me an error.
> -----------------------------------------------------------
> ??? Undefined function or variable 'b'.

Are you looking to plot blue lines between the points? Remember, line
specification are _strings_, so:

plot(JD(k),TAIminusUTC(k),'-b')

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

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.

Contact us