Plotting different graphs for different variables using loops

How do I plot different variables such as: qq1, qq2, qq3, qq4, qq5 in different plots using a loop? Say these qq terms contain values. Could I use a for loop?

1 Kommentar

Stephen23
Stephen23 am 22 Mär. 2017
Bearbeitet: Stephen23 am 22 Mär. 2017
Please read the MATLAB documentation, which states "A frequent use of the eval function is to create sets of variables such as A1, A2, ..., An, but this approach does not use the array processing power of MATLAB and is not recommended."
Here are some pages that explain why accessing variable names dynamically is a bad idea:
You should use indexing: indexing is much more efficient, easier to use, faster, much less buggy, and much less obfuscated than any hack code that accesses the variable names dynamically.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Star Strider
Star Strider am 22 Mär. 2017
First, rename them as elements of a cell array, such as:
qq{1} = ...;
qq{2} = ...;
Then you can use a loop. Note the curly brackets ‘{}’ denoting cell array indexing.

Gefragt:

am 22 Mär. 2017

Beantwortet:

am 22 Mär. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by