I want to simplify the text of a program some in the followingway: instead of li
ID: 3612143 • Letter: I
Question
I want to simplify the text of a program some in the followingway: instead of listing plot(t,x(:,1)) xlabel('t'), ylabel('x(1)') title('x(1)~A~O2 vs. t) figure for 13 different graphs, I want to make a for loop with the 1replaced by i where i=1:13. The problem is I want the titles ofeach graph to be different and it just prints whatever is withinthe quotes. How can I print different titles of graphs within a forloop? I'll give lifesaver points. Thanks. I want to simplify the text of a program some in the followingway: instead of listing plot(t,x(:,1)) xlabel('t'), ylabel('x(1)') title('x(1)~A~O2 vs. t) figure for 13 different graphs, I want to make a for loop with the 1replaced by i where i=1:13. The problem is I want the titles ofeach graph to be different and it just prints whatever is withinthe quotes. How can I print different titles of graphs within a forloop? I'll give lifesaver points. Thanks.Explanation / Answer
Simply create an array of the titles and labels that you wantbeforehand. graphYLabels = {'x(1)' 'x(2)' ... }; graphTitle = {'x(1)~A~O2 vs. t' 'x(2)~A~O2 vs. t' ... }; Then in the loops, simply change your ylabel and title linesto: ylabel( graphYLabels(i) ); title( graphTitle(i) ); Alternatively, you can use string formatting or concatenation to dothe same job strictly within the for loop like so (this is thestring formatting method. If you want the concatenationmethod as well, just let me know, they're basically the same, justdifferent syntaxes): ylabel( sprintf( 'x(%d)', i ) ); title( sprintf( 'x(%d)~A~O2 vs. t', i ); Let me know if you need any other clarifications or help, and I'llbe glad to see what I can do.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.