for loops and arrays

4 views (last 30 days)
harley
harley on 25 Aug 2014
Commented: Star Strider on 25 Aug 2014
Hello,
part of a script below. How can i write this without typing every in c(j-1,5). I am planning on expanding the array. Thanks
for j=2:t_dom+1
cc=A\(B*[c(j-1,2);c(j-1,3);c(j-1,4);c(j-1,5);c(j-1,6);c(j-1,7);c(j-1,8)]);
for kk=1:length(cc)
c(j,kk+1)=cc(kk);
end
end

Accepted Answer

Star Strider
Star Strider on 25 Aug 2014
See if this improves things:
cc=A\(B*[c(j-1,2:8)]');
This assumes c(j-1,2:8) is a row vector to start. If it is a column vector, leave off the transpose (') operator:
cc=A\(B*[c(j-1,2:8)]);
  2 Comments
harley
harley on 25 Aug 2014
thanks
Star Strider
Star Strider on 25 Aug 2014
My pleasure!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!