How to apply for loop while using functions?

Hello, actually i couldn't describe my problem clearly. I have codes below:
fft_1=fft2(double(JD1));
fft_genlik1=abs(fftshift(fft_1));
max_value1=max(fft_genlik1(:));
fft_2=fft2(double(JD2));
fft_genlik2=abs(fftshift(fft_2));
max_value2=max(fft_genlik2(:));
fft_3=fft2(double(JD3));
fft_genlik3=abs(fftshift(fft_3));
max_value3=max(fft_genlik3(:));
...
(and anothher 7)
i want to do all these three process on a for loop. Is it possible, if it is, how?

4 件のコメント

dpb
dpb 2021 年 11 月 20 日
Sure, just don't use independently sequentially-named/numbered variables -- use arrays or cell arrays instead.
Emre Mert Aygormus
Emre Mert Aygormus 2021 年 11 月 20 日
編集済み: Emre Mert Aygormus 2021 年 11 月 20 日
as i understand, you say that create a array that contains variable names such as fft_1, fft_2 ... and then i should use this array in for loop, rigth?
Stephen23
Stephen23 2021 年 11 月 20 日
編集済み: Stephen23 2021 年 11 月 20 日
"you say that create a array that contains variable names such as fft_1, fft_2 ..."
No. Do not create an array of "variable names".
Create a cell array (or struct, table, ND array) that contains your actual data arrays.
Then your loop is very simple with basic indexing.
Emre Mert Aygormus
Emre Mert Aygormus 2021 年 11 月 20 日
I got it, thanks a lot to both you sirs. I am really appreciated.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2021b

質問済み:

2021 年 11 月 20 日

編集済み:

2021 年 11 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by