フィルターのクリア

Loop generation doubt.

1 回表示 (過去 30 日間)
Martin Thomas
Martin Thomas 2020 年 8 月 22 日
コメント済み: the cyclist 2020 年 8 月 23 日
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

採用された回答

the cyclist
the cyclist 2020 年 8 月 22 日
% DO NOT USE THESE. USE YOUR DATA. THESE ARE FOR AN EXAMPLE ONLY
T = rand(160547,1);
A = rand(44880,1);
k = rand(size(A));
w = rand(size(A));
%%%%%% Only use the code below %%%%%
% Preallocate memory for E
E = zeros(1,160547);
% Calculate E
for ii = 1:size(E2,2)
E(ii) = sum(A.*cos(k-(w.*T(ii))));
end
  11 件のコメント
Martin Thomas
Martin Thomas 2020 年 8 月 23 日
hey one more doubt, i think you know the fft, in the fft amplitude plot from the above code you can see lot of peaks, moreover if i do the fft on any signal it will give me some more additional values is that possible to remove those values from that.
the cyclist
the cyclist 2020 年 8 月 23 日
I don't really use fft. I would open a new question, and upload an image of the plot using INSERT again, along with the code that generates it.
Try to be very clear about your exact question.

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

その他の回答 (1 件)

the cyclist
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
Martin Thomas 2020 年 8 月 22 日
I have a time vector of
T=1:(1/128):1200 160547x1 double
A= fft results (amplitude) 44880x1 double
k=(same length of A) 44880x1 double
w= frequency (same lenth of A) 44880x1 double
The problem is T does not have equal length so i can't do the E. the only way i need to do is calculating first row of A,k and w with varying T will get a result same i need to be don in the second row, thrid until the end of the A,k and w value. then i wll sum it up
E = SUM(A.*cos(k-(w.*t')));
Martin Thomas
Martin Thomas 2020 年 8 月 22 日
So there willbe 160547x44880 or 44880x160547 matrix after summing up the values ther will be 160547x1 double matrix

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by