フィルターのクリア

Summation in MATLAB in 4 dimenstion

1 回表示 (過去 30 日間)
JAVAD
JAVAD 2023 年 2 月 16 日
コメント済み: JAVAD 2023 年 2 月 20 日
I have a matrix with 4 dimentions.
I should sum values.
w(i,j,k,t)
k is constant.t is time
My problem is how to add t to loap.
for example for t=1, give me the results but I repeate up to 12. I need sumation for each t seprately and save it and then repeat it for 12 times.
How can do it?
sum=0
for i=1:i
for j=97:176
if w(i,j,15,t)<0
sum=sum+w(i,j,15,t)/(pm(i,j)*pn(i,j))
end
end
end
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 2 月 16 日
We advise against using sum as the name of a variable. It is very common for people who use sum as a variable name to find that they also need to call upon the MATLAB sum function. And besides, it confuses the readers.

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

採用された回答

Torsten
Torsten 2023 年 2 月 16 日
for t = 1:T
s(t) = 0;
for i=1:i <---- for i=1:i does not make sense
for j=97:176
if w(i,j,15,t)<0
s(t)=s(t)+w(i,j,15,t)/(pm(i,j)*pn(i,j))
end
end
end
end
  1 件のコメント
JAVAD
JAVAD 2023 年 2 月 20 日
Thanks
It works!

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

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2023 年 2 月 16 日
S = sum(X,DIM) sums along the dimension DIM
  2 件のコメント
JAVAD
JAVAD 2023 年 2 月 16 日
移動済み: Fangjun Jiang 2023 年 2 月 16 日
Thanks for your response.
I use it before but I think that in my case it doesnot work. If you think work, can you rewrite my codes to understand it better.
Fangjun Jiang
Fangjun Jiang 2023 年 2 月 16 日
You need to clarify
  1. what is "i" in "for i=1:i"
  2. assume t is 1:12?
  3. pm? pn?

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

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by