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:
loop

Subject: loop

From: Sam

Date: 2 Apr, 2012 15:02:13

Message: 1 of 2

There is a vector Data, which is:

Data=rand(1,41)';

I need to define two different outputs for this Data

N=(1:1:6);
n = length(N);
DataIndex = zeros((n^3+5*n+6)/6,n);
p = n:-1:1;
s = 0;
for k = n:-1:n-3
    c = nchoosek(p,k);
    for m = 1:size(c,1)
        s = s + 1;
        DataIndex(s,c(m,:)) = N(c(m,:));
    end
end

DIndex=DataIndex(2:end,:);

% Index indicating which values we need in both Data and DIndex (where the values are zero) for example

Out1_1=Data(7)-Data(1)*Data(2);
Out1_15=Data(21)-Data(5)*Data(6);
Out2_16=Data (22)-Data(1)*Data(2)*Data(3);
Out2_35=Data (41)-Data(4)*Data(5)*Data(6);

I need to write a loop that took the data and excute this function.

Thanks,

Sam

Subject: loop

From: Roger Stafford

Date: 2 Apr, 2012 20:51:11

Message: 2 of 2

"Sam " <sameiwater@gmail.com> wrote in message <jlcf1k$l3a$1@newscl01ah.mathworks.com>...
> There is a vector Data, which is:
>
> Data=rand(1,41)';
>
> I need to define two different outputs for this Data
>
> N=(1:1:6);
> n = length(N);
> DataIndex = zeros((n^3+5*n+6)/6,n);
> p = n:-1:1;
> s = 0;
> for k = n:-1:n-3
> c = nchoosek(p,k);
> for m = 1:size(c,1)
> s = s + 1;
> DataIndex(s,c(m,:)) = N(c(m,:));
> end
> end
>
> DIndex=DataIndex(2:end,:);
>
> % Index indicating which values we need in both Data and DIndex (where the values are zero) for example
>
> Out1_1=Data(7)-Data(1)*Data(2);
> Out1_15=Data(21)-Data(5)*Data(6);
> Out2_16=Data (22)-Data(1)*Data(2)*Data(3);
> Out2_35=Data (41)-Data(4)*Data(5)*Data(6);
>
> I need to write a loop that took the data and excute this function.
>
> Thanks,
>
> Sam
- - - - - - - - -
  A partial answer is that somewhere you will need the expression:

 Data(ix)-prod(Data(DataIndex(ix,:)==0))

This will give you the right sides of your indicated outputs for a general index 'ix' into 'Data'. I have no idea how you want your two outputs indexed however, so you will have to figure out how to use this to generate them in for-loops.

Roger Stafford

Tags for 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