필터 지우기
필터 지우기

How to use fplot to plot a function file with single input mutiple outputs?

조회 수: 2 (최근 30일)
sara
sara 2015년 11월 3일
댓글: Guillaume 2015년 11월 3일
Hello, I have a function file that contains 5 outputs and one input. I would like to plot the outputs on a single plot against a range of input values. fplot works nicely when I have a single output but does not work for multiple outputs (it doesn't plot all 5 outputs). Please help me. Thank you

답변 (1개)

Guillaume
Guillaume 2015년 11월 3일
You'll have to explain what 'does not work for multiple outputs' mean exactly:
fn = @(x) [sin(x), cos(x), sin(x.^2), cos(x.^2), sin(x) + cos(x)]; %function with 5 outputs
fplot(fn, [-pi, pi])
works perfectly well. Do you get an error? If so, what is the error?
  댓글 수: 2
sara
sara 2015년 11월 3일
I mean it only plots one of the outputs. So I have a function file with 3 outputs: function [ x, y, z] = myfunction( A )
and I would like to plot x, y, z with respect to A using fplot. When I do the following, only one of the outputs get plotted. hold on fplot('myfunction',[0.2 0.5])
Guillaume
Guillaume 2015년 11월 3일
The outputs need to be concatenated into a row vector for fplot to work.
You can either rewrite your function as:
function [x(:, 1), x(:, 2), x(:, 3)] = myfunction(A)
%...
end
Or use an intermediary function:
function x = catmyfunction(A)
[x(:, 1), x(:, 2), x(:, 3)] = myfunction(A);
end
then
fplot(@catmyfunction, [0.2, 0.5]);

댓글을 달려면 로그인하십시오.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by