フィルターのクリア

how to find a mean across rows

4 ビュー (過去 30 日間)
harley
harley 2013 年 10 月 4 日
コメント済み: Image Analyst 2013 年 10 月 5 日
i have a code that produces a matrix, i want it to find the mean across the rows rather than down each column. i tried the below but keep getting an error.
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
lambdaMJ = 7.2;
MJ_Flow = (30/60)*2;
A = 100;
B = 70;
C = 4;
D = B + C;
E = A - B - C;
for a = 1:5;
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,E],MJ_Flow);
Major11(a) = mean(MJ_V11,2); %CANT GET THIS TO WORK
end

採用された回答

Image Analyst
Image Analyst 2013 年 10 月 4 日
編集済み: Image Analyst 2013 年 10 月 5 日
What is the loop for? It's not needed. Just do this:
Major11 = mean(MJ_V11,2);
If MJ_V11 changes inside the loop, then you can still have it in the loop:
for a = 1 : 5 % No() or ; needed
MJ_V11 = whatever.....
Major11(a) = mean(MJ_V11(a,:),2);
end
Note how I added an index to Major11 so that it doesn't get overwritten every time.
  8 件のコメント
harley
harley 2013 年 10 月 5 日
編集済み: harley 2013 年 10 月 5 日
thanks again, i tried the below but it just gives me the first 5 values of the first column/ loop.
Major11(a) = mean(MJ_V11(a,:),2);
Image Analyst
Image Analyst 2013 年 10 月 5 日
That's because you had
for a = 1:5
If you want all the rows, you need to go over all the rows, not just 5 of them:
[rows, columns] = size(MJ_V11);
for a = 1 : rows

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

その他の回答 (0 件)

カテゴリ

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