Loop generation doubt.
古いコメントを表示
Hi,
I need to create a loop. I have to do a numerical analysis of thousands of data points.
My equation is,
E=A*cos(k-(w*t))
I have A,k and w three of them have same length 1x10. In the case of t which i have 1x50.
what i have to do is i need to take the first value of A,k and w and vary t (means run with range of values) . I need to do the same processs for the rest of the rows of A,k and w and vary t.
To be more precise.
A k w T
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
N N N 5
6
N
the equation will be
First calculation need to be
E=1*cos(1-(1*(1....N)))
second
E=2*cos(2-(2*(1....N)))
.......
continue upto length of A,k,w
採用された回答
その他の回答 (1 件)
the cyclist
2020 年 8 月 22 日
編集済み: the cyclist
2020 年 8 月 22 日
You don't need to use a loop. MATLAB will do vectorized calculations.
If you have a fairly recent version of MATLAB, you can do this using implicit expansion of the vectors:
% Make up some data
A = rand(1,10);
k = rand(1,10);
w = rand(1,10);
t = rand(1,50);
% Calculate E
E = A.*cos(k-(w.*t'));
The output E will be 50x10.
Note that I took the transpose of t, and also used element-wise multiplication and not matrix multiplication. You can read about the difference here.
5 件のコメント
Martin Thomas
2020 年 8 月 22 日
Martin Thomas
2020 年 8 月 22 日
the cyclist
2020 年 8 月 22 日
The only code you need is the last line I wrote:
% Calculate E
E = A.*cos(k-(w.*t'));
The other lines of code are just making up some pretend input values, which I used to make sure that last line worked. You should just use your values for A, k, and w.
I didn't really understand your other comments, so if that doesn't help, maybe try to explain it again?
Martin Thomas
2020 年 8 月 22 日
Martin Thomas
2020 年 8 月 22 日
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!