naming matrix with a specific pattern

2 Ansichten (letzte 30 Tage)
SANG GYU LEE
SANG GYU LEE am 30 Sep. 2016
Bearbeitet: Stephen23 am 25 Jun. 2019
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?

Akzeptierte Antwort

James Tursa
James Tursa am 30 Sep. 2016
Please don't do this! It will be very hard to maintain your code. See this link for alternatives:

Weitere Antworten (1)

dpb
dpb am 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...

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by