index exceeds matrix dimensions
이전 댓글 표시
I'm having an issue with the following code that models token ring behaviour:
clc
clear all
syms k C W
E(C) = ((50*2.15e-4)/(1-(50*k*2.215e-4)));
E(W) = (((2.637e-8)*(1-0.02215*k + (1.227e-4)*k^2) - (1.15e-4)*(1-0.011075*k))/ (0.0215*(1-0.02215*k + (1.227e-4)*k^2) - (((2.31125e-4)*k)*(1-0.011075*k))));
hold all
fplot(((50*2.15e-4)/(1-(50*k*2.215e-4))))
xlabel('lamda');
ylabel('E(C)');
title('Graph of E(C) against Lamda','FontSize',12);
when this program runs the error 'index exceeds matrix dimensions' appears and states a problem with the line beginning flpot. anyone know how to fix this?
댓글 수: 1
John BG
2018년 1월 15일
Hi Nick
What version of MATLAB are you using?
With latest release your code works ok:

답변 (2개)
Star Strider
2018년 1월 14일
The fplot function is expecting a function and a range for the independent variable.
Try this:
fplot(@(k) ((50*2.15e-4)./(1-(50*k*2.215e-4))), [-1 1])
댓글 수: 2
Nick
2018년 1월 14일
Star Strider
2018년 1월 14일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
Walter Roberson
2018년 1월 14일
The code runs to completion on newer versions of MATLAB. A couple of releases ago, fplot was improved to support symbolic expressions.
However, note that when you define
E(C) = expression1;
E(W) = expression2;
then you are overwriting E with the second statement. The statements are equivalent to
E = symfun(expression1, C);
E = symfun(expression2, W);
The syntax does not define two different functions, E subscript C and E subscript W.
Your fplot does not use either one at the moment though.
카테고리
도움말 센터 및 File Exchange에서 Code Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!