Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] matlab help needed regarding for loop

Status
Not open for further replies.

sayfee

Junior Member level 1
Junior Member level 1
Joined
Apr 22, 2011
Messages
19
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,389
f=[1 2 3 4];
c=[1 2 3 4 ; 5 6 7 8; 9 10 11 12; 13 14 15 16];

bb(1,1)=f(1)*c(1,1)*0+f(1)*c(1,2)*1+f(1)*c(1,3)*2+f(1)*c(1,4)*3;

bb(1,2)=f(2)*c(1,1)*0+f(2)*c(1,2)*1+f(2)*c(1,3)*2+f(2)*c(1,4)*3;

bb(1,3)=f(3)*c(1,1)*0+f(3)*c(1,2)*1+f(3)*c(1,3)*2+f(3)*c(1,4)*3;

bb(1,4)=f(4)*c(1,1)*0+f(4)*c(1,2)*1+f(4)*c(1,3)*2+f(4)*c(1,4)*3;


bb(2,1)=f(1)*c(2,1)*0+f(1)*c(2,2)*1+f(1)*c(2,3)*2+f(1)*c(2,4)*3;

bb(2,2)=f(2)*c(2,1)*0+f(2)*c(2,2)*1+f(2)*c(2,3)*2+f(2)*c(2,4)*3;

bb(2,3)=f(3)*c(2,1)*0+f(3)*c(2,2)*1+f(3)*c(2,3)*2+f(3)*c(2,4)*3;

bb(2,4)=f(4)*c(2,1)*0+f(4)*c(2,2)*1+f(4)*c(2,3)*2+f(4)*c(2,4)*3;



bb(3,1)=f(1)*c(3,1)*0+f(1)*c(3,2)*1+f(1)*c(3,3)*2+f(1)*c(3,4)*3;

bb(3,2)=f(2)*c(3,1)*0+f(2)*c(3,2)*1+f(2)*c(3,3)*2+f(2)*c(3,4)*3;

bb(3,3)=f(3)*c(3,1)*0+f(3)*c(3,2)*1+f(3)*c(3,3)*2+f(3)*c(3,4)*3;

bb(3,4)=f(4)*c(3,1)*0+f(4)*c(3,2)*1+f(4)*c(3,3)*2+f(4)*c(3,4)*3;


bb(4,1)=f(1)*c(4,1)*0+f(1)*c(4,2)*1+f(1)*c(4,3)*2+f(1)*c(4,4)*3;

bb(4,2)=f(2)*c(4,1)*0+f(2)*c(4,2)*1+f(2)*c(4,3)*2+f(2)*c(4,4)*3;

bb(4,3)=f(3)*c(4,1)*0+f(3)*c(4,2)*1+f(3)*c(4,3)*2+f(3)*c(4,4)*3;

bb(4,4)=f(4)*c(4,1)*0+f(4)*c(4,2)*1+f(4)*c(4,3)*2+f(4)*c(4,4)*3;

bb

here bb is 4*4 matrix i want all the result in this matrix
and i want to do this using for loop but cant do it...can anybody help me plzzz :-(
 

Hi sayfee,

here is your code. I tested it for all possible values and it is working fine.

***************************************************************************
clear all;
f=[1 2 3 4];
c=[1 2 3 4 ; 5 6 7 8; 9 10 11 12; 13 14 15 16];
n = [0 1 2 3];
bb = zeros(4,4);
for k = 1 : 4
%k = 1; % just for test
%m = 2; % just for test
for m = 1 : 4
bb(k,m) = sum(f(m).*c(k,:).*n);
end % m
end % k
bb

Don't forget to press help me,

Cheers,
MAK
 
  • Like
Reactions: sayfee

    sayfee

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top