naming matrix with a specific pattern
1 view (last 30 days)
Show older comments
I want to make a function that uses input a positive integer, and the number of outputs depends on the input. For example, if I put 5 as an input, the outputs will be five matrix: named from a_1 to a_5. If I put an input of 50, the outputs will be from a_1 to a_50. It will be very time consuming if I make a code of function that specifies all the names of outputs. Thus, I would rather give a specific pattern for the outputs. Is it possible in Matlab?
2 Comments
Accepted Answer
James Tursa
on 30 Sep 2016
Please don't do this! It will be very hard to maintain your code. See this link for alternatives:
0 Comments
More Answers (1)
dpb
on 30 Sep 2016
Possible but a_very_BAD_idea(tm) indeed. How are you going to write the consumer of this function if you have 50 separate outputs???!!! You're back to the same coding problem every time you try to use it, not just when writing it.
Use either an array that the user can query as to size or at worst a structure w/ named fields that can be programmatically iterated over. The latter is, in my opinion, only a small step above the first in a design, but perhaps with an explanation of why you want to do this and how it would be useful to have so many individual variables you might convince somebody...
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!