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

New to MATLAB?

Saving to structured variable in loop

Asked by Jakub

Jakub (view profile)

on 14 Mar 2013

Hi This is part of my code:

for i=1:18
  for j=i+1:19
     x = data(i,:);
     y = data(j,:);
     wcoh.(i,j)=wcoher(x,y);
  end
end

Function wcoher computes from two rows of data one matrix. But i have 19 rows of data. And i want to compute wcoher for each pair. So the result would be structured variable for example wcoh->inside it variables 1-2,1-3,1-4,....5-6,...18-19-> and inside matrix computed by wcoher function.

Thx for help!!

2 Comments

Andrei Bobrov

Andrei Bobrov (view profile)

on 14 Mar 2013

What are return wcoher ? Scalar or array?

Jakub

Jakub (view profile)

on 14 Mar 2013

matrix

Jakub

Jakub (view profile)

Products

No products are associated with this question.

1 Answer

Answer by Alessandro

Alessandro (view profile)

on 14 Mar 2013
Edited by Alessandro

Alessandro (view profile)

on 15 Mar 2013
Accepted answer

If I understand you right you wannt to have:

wcoh= cell(Ny,Nx);
for i=1:Ny 
   for j=i+1:Nx
     x = data(i,:); y = data(j,:); 
     wcoh{i,j}=wcoher(x,y);
      end
  end

1 Comment

Jakub

Jakub (view profile)

on 15 Mar 2013

Thanks, it works perfectly!

Alessandro

Alessandro (view profile)

Contact us