フィルターのクリア

??? Subscripted assignment dimension mismatch

2 ビュー (過去 30 日間)
harley
harley 2013 年 10 月 5 日
コメント済み: Cedric 2013 年 10 月 5 日
how do I fix this assignment error?
lambdaMJ = 7.2;
MJ_Flow = (30/60)*2;
A = 100;
B = 1;
C = 70;
D = 4;
E = C + D;
F = A - C - D;
MJ_start=0;
for a=1:100
Num_cylces = 1;
XMJ=(poissrnd(lambdaMJ, A, Num_cylces));
lambdaMJ_sec(a) = mean(XMJ)/10;
%
FMJ_cars_wait = @(T11,MJ_V11) (lambdaMJ_sec(a));
[T11,MJ_V11] = ode45(FMJ_cars_wait,[0,F],MJ_start);
R_G_MJ = MJ_V11(end:end);
%
FMJ_cars_wait_2 = @(T12,MJ_V12) (lambdaMJ_sec(a) - MJ_Flow);
[T12,MJ_V12] = ode45(FMJ_cars_wait_2,[F,A],R_G_MJ);
%
Major_end(a)=MJ_V12(end);
MJ_start=MJ_V12(end);
if MJ_start < 0
MJ_start=0;
else
MJ_start=MJ_start;
end
%
Major1(:,a) = MJ_V11;
end
??? Subscripted assignment dimension mismatch.
Error in ==> Untitled2 at 30
Major1(:,a) = MJ_V11;

採用された回答

Cedric
Cedric 2013 年 10 月 5 日
編集済み: Cedric 2013 年 10 月 5 日
First:
doc interp1
and once you understand roughly what it does and its input parameters, I guess that you could modify your code a little bit as follows (untested):
lambdaMJ = 7.2;
MJ_Flow = (30/60)*2;
A = 100;
B = 1;
C = 70;
D = 4;
E = C + D;
F = A - C - D;
MJ_start=0;
% NEW
n = 100 ;
step = 0.5 ;
tGrid = (0:step:F).' ;
lambdaMJ_sec = zeros(1, n) ;
Major_end = zeros(1, n) ;
Major1 = zeros(length(tGrid), n) ;
for a = 1:n % Updated: upper bound.
Num_cylces = 1;
XMJ=(poissrnd(lambdaMJ, A, Num_cylces));
lambdaMJ_sec(a) = mean(XMJ)/10;
%
FMJ_cars_wait = @(T11,MJ_V11) (lambdaMJ_sec(a));
[T11,MJ_V11] = ode45(FMJ_cars_wait,[0,F],MJ_start);
R_G_MJ = MJ_V11(end:end);
%
FMJ_cars_wait_2 = @(T12,MJ_V12) (lambdaMJ_sec(a) - MJ_Flow);
[T12,MJ_V12] = ode45(FMJ_cars_wait_2,[F,A],R_G_MJ);
%
Major_end(a)=MJ_V12(end);
MJ_start=MJ_V12(end);
if MJ_start < 0
MJ_start=0;
end % Updated: no else clause.
%
Major1(:,a) = interp1(T11, MJ_V11, tGrid); % Updated: interpolate.
end
  2 件のコメント
harley
harley 2013 年 10 月 5 日
thanks Cedric
Cedric
Cedric 2013 年 10 月 5 日
編集済み: Cedric 2013 年 10 月 5 日
You're welcome. I didn't really get into the code .. is it correct that Num_cycles is constant and equal to 1 for all iterations of the loop? If so, it could be defined outside before the loop.

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2013 年 10 月 5 日
編集済み: Matt J 2013 年 10 月 5 日
Make MJ_V11 the same size as Major1(:,a)
  5 件のコメント
Image Analyst
Image Analyst 2013 年 10 月 5 日
Matt, we went over all that in his original question http://www.mathworks.com/matlabcentral/answers/89151-how-to-find-a-mean-across-rows. I told him you can't stick a whole vector into a single element. Not sure why he abandoned that discussion, and asked all over again here.
Cedric
Cedric 2013 年 10 月 5 日
See my answer.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by