naming matrix with a specific pattern

조회 수: 2 (최근 30일)
SANG GYU LEE
SANG GYU LEE 2016년 9월 30일
편집: Stephen23 2019년 6월 25일
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?

채택된 답변

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

추가 답변 (1개)

dpb
dpb 2016년 9월 30일
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...

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by