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:
Output to vector

Subject: Output to vector

From: Nick

Date: 5 Dec, 2009 01:21:07

Message: 1 of 3

Below is my code for arbitrage analysis on DIA and the DOW

I need the x and the i to output to seperate vectors.

If someone can please help me I cant find how to do this anywhere.

clear
clc

load DIADOW.m

DIA = DIADOW(:,1);
DOW = DIADOW(:,2);

N = length(DIA);
tol = 20;
for i = 1:N
    if abs(DIA(i)*100-DOW(i))> tol
        x = DIA(i)*100 - DOW(i)
        time = i;
    end
    
end

Subject: Output to vector

From: Jane

Date: 5 Dec, 2009 08:02:05

Message: 2 of 3

"Nick " <nfjonesme@gmail.com> wrote in message <hfcci3$1d9$1@fred.mathworks.com>...
> Below is my code for arbitrage analysis on DIA and the DOW
>
> I need the x and the i to output to seperate vectors.
>
> If someone can please help me I cant find how to do this anywhere.
>
> clear
> clc
>
> load DIADOW.m
>
> DIA = DIADOW(:,1);
> DOW = DIADOW(:,2);
>
> N = length(DIA);
> tol = 20;
> for i = 1:N
> if abs(DIA(i)*100-DOW(i))> tol
> x = DIA(i)*100 - DOW(i)
> time = i;
> end
>
> end

Funny, someone else was asking about some very similar code the other day!

If instead of x= you use x(i)= then the output of x will be a vector.

Subject: Output to vector

From: Sadik

Date: 5 Dec, 2009 09:36:04

Message: 3 of 3

Actually, if you use x(i) instead, you will be skipping some i values because it is inside an if statement.

You had better use the following:

clear
clc

load DIADOW.m

DIA = DIADOW(:,1);
DOW = DIADOW(:,2);

N = length(DIA);
tol = 20;
iVector = [];
xVector = [];
for i = 1:N
    if abs(DIA(i)*100-DOW(i))> tol
        x = DIA(i)*100 - DOW(i)
        time = i;
        xVector(end+1) = x;
        iVector(end+1) = i;
    end
end

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