How to index in for cycle

4 ビュー (過去 30 日間)
Filip Konecny
Filip Konecny 2018 年 3 月 1 日
編集済み: jonas 2018 年 3 月 2 日
Hello,
I have a function called Intersection_elipsoid. The functions works like that:
[lat,lon]=Intersection_elipsoid() It gives me latitude and longitude.
I want to do a for cycle and use this function with matrix X. In matrix X there are some values I use in the intersection_elipsoid function.
The for function is called location and should go through matrix X and use Intersection_elipsoid function and give me some outputs.
The problem is that the for cycle gives me only the first value from the Intersection_elipsoid function. I do not know how to "say" to the for cycle that it should give me both values. If I write: [final_lat,final_lon]=Location(X)
m=length(X)
for i=1:m
if (X(i,5)==6) && (X(i,6)==12)
[XY,YX](i,1:2)=Intersection_elipsoid
is not valid in syntax.
If I write:
[final_lat,final_lon]=Location(X)
m=length(X)
for i=1:m
if (X(i,5)==6) && (X(i,6)==12)
final_lat(i,1)=Intersection_elipsoid
It gives me only the first value.
Is there a way how to do it?
Thank you

採用された回答

jonas
jonas 2018 年 3 月 1 日
編集済み: jonas 2018 年 3 月 2 日
lat(i),lon(i)]=Intersection_elipsoid()
Consider preallocating your variables to avoid slow loops, by e.g. typing 'lat=nan(1,lenght(m))' before looping over m
  2 件のコメント
Stephen23
Stephen23 2018 年 3 月 2 日
Array preallocation? It is helpful when are you giving advice to beginners to show basic MATLAB concepts, like how to preallocate arrays.
jonas
jonas 2018 年 3 月 2 日
Thank you, will do in the future

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by