フィルターのクリア

Display the calculation result

3 ビュー (過去 30 日間)
Zoe Lin
Zoe Lin 2018 年 5 月 21 日
編集済み: Zoe Lin 2018 年 5 月 21 日
Dear :
I have 4(declared for cont) datas of weight,my code is following:
clc
clear all
weight=[1 1 1 1;2 2 2 2;3 3 3 3;4 4 4 4];
ax=[1 2 3 4;1 2 3 4;1 2 3 4;1 2 3 4];
Beta=[0 0 0 0];
cont=length(weight);
for cont_I=1:cont
Etotalx=zeros(cont,cont_I);
for g=1:4
Etotalx(:,cont_I)=Etotalx(:,cont_I)+weight(cont_I,g).*ax(:,g)*exp(1j*Beta(g));
end
end
But the display result only has the last result(the 4th data),others(the former ones) are 0.
The result like this picture:
This is my problem,need everyone's instruction and advice,thank for first.

採用された回答

Shrestha Kumar
Shrestha Kumar 2018 年 5 月 21 日
Hi, You are declaring a zero matrix each time inside the loop i.e for the first iteration you declare a 4*1 zero matrix and then update the first column, in the second iteration you declare a 4*2 zero matrix and update only the second column and the first column remains zero and so on. The solution for the problem is to declare a 4*4(i.e cont * cont) zero matrix outside the loop and then update the columns.
Etotalx = zeros(cont,cont); for cont_I = 1:cont for g=1:4 ....
  1 件のコメント
Zoe Lin
Zoe Lin 2018 年 5 月 21 日
編集済み: Zoe Lin 2018 年 5 月 21 日
Dear Shrestha Kumar:
Thanks a lot,thank you for your big help,thanks~

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by