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!