How to implement 2 vectors in a for-loop to get a matrix?

1 回表示 (過去 30 日間)
Lu Da Silva
Lu Da Silva 2021 年 3 月 5 日
回答済み: Rik 2021 年 3 月 5 日
I use a for-loop to define the profile of an airfoil. It depends on sundry factors, two of which (a and b) are variables.
In order to plot the airfoil I set random values for a and b.
However, since I need to find an airfoil with a specific thickness, I need to calculate all possible airfoil profiles and then compare thickness values until I find the requested one.
a and b should both range from 0 to 1 but I don't know how to apply that into my code... I tried making 2 vectors:
a=0:0.001:1;
b=0:0.001:1;
but in vain, as it resulted in a vecor instead of a matrix (it used value #1 of vector a with value #1 of vecor b, then moved to value #2(a) with value #2(b) instead of giving all possible solutions (matrix)).
Could you help me out? Should I create another 2 for-loops for a and b?
Thanksss,
Lu

回答 (1 件)

Rik
Rik 2021 年 3 月 5 日
[A,B]=ndgrid(a,b);
Then a single for-loop will do

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by