Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

/edit Nevermind i figured it out, i now have:

    Do[AppendTo[sr, 
   StateResponse[{StateSpaceModel[{amtrx[[i]], b, c, d}], {rad3, 
      rad4}}, M1[t], {t, 0, 5}]], {i, 9}];
Do[Print[Plot[sr[[i]][[1]], {t, 0, 5}, PlotLegends -> i]], {i, 9}]

and it works

If have tried

Do[Plot[StateResponse[{StateSpaceModel[{amtrx[[i]], b, c, d}], {rad3, 
  rad4}}, M1[t], {t, 0, 5}][[1]], {t, 0, 5}], {i, 9}]

as well as For[x = 1, x < 10, x++, Plot[StateResponse[{StateSpaceModel[{amtrx[[x]], b, c, d}], {rad3, rad4}}, M1[t], {t, 0, 5}][[1]], {t, 0, 5}]]

but for some reason i keep getting the following error:

StateResponse::nsymb: 0.00010214285714285715` must be a symbol. >>

However, when i remove the Plot from the loop and instead use print, like so:

Do[Print[StateResponse[{StateSpaceModel[{amtrx[[i]], b, c, d}], {rad3,
  rad4}}, M1[t], {t, 0, 5}]], {i, 9}]

it does give the output i expect, namely 9 times:

{InterpolatingFunction[{{0.,5.}},<>][t],InterpolatingFunction[{{0.,5.}},<>][t]}

so why when i want to build a Plot inside the loop does it break all of a sudden, and how do i fix this?

share|improve this question

closed as off-topic by Yves Klett, rasher, gpap, m_goldberg, bobthechemist Apr 21 at 14:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Yves Klett, rasher, gpap, m_goldberg, bobthechemist
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Use Evaluate. Do[Plot[Evaluate@StateResponse[{StateSpaceModel[{amtrx[[i]], b, c, d}], {rad3, rad4}}, M1[t], {t, 0, 5}][[1]], {t, 0, 5}], {i, 9}] –  Suba Thomas Apr 21 at 14:11

Browse other questions tagged or ask your own question.