필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How can I create series of equations to graph, that might have a different number of equations every time, without using dynamic variable naming?

조회 수: 1 (최근 30일)
I'm trying to write myself a nice Matlab program that lets me input arguments based on prompts and will graph the equations I put in. I need it to be able to graph anywhere from 1-10 equations at a time, but i cant figure out how to set them all up with names, without naming variables dynamically with something like eval. I know dynamic variable naming is bad practice, but I don't know of another way to do it.
(I am trying to improve my proficiency in mat lab beyond using it as a large graphing calculator, and I know the graphing commands so this lets me learn about script writing and know what I was trying to draw, so I can tell what went wrong)
I would also appreciate knowing if there are multiple methods to achieve this.

답변 (1개)

José-Luis
José-Luis 2017년 8월 29일
편집: José-Luis 2017년 8월 29일
You can place function handles in cell arrays:
funArray = cell(2,1);
funArray{1} = @(x) x.^2;
funArray{2} = @(x) 3.*x + 5;
funArray{1}(3)
funArray{2}(3)
funArray{1}(1:5)
fplot(funArray{1},[-5,5])
In order to parse your inputs to a function handle, you could try using str2func() which is, allegedly, a step above eval().

Community Treasure Hunt

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

Start Hunting!

Translated by