Loop over an array or list of vectors
古いコメントを表示
Is there a way to loop over an array of signal vectors in Matlab? Python has a way to do it using for loop like:
v1 = [] //signal vector1
v2 = [] //signal vector2
arrv = [v1, v2] //array of signal vectors
for v in arrv:
print len(v)
It would be great if someone can suggest a similar solution if it exists.
2 件のコメント
Sudhakar Shinde
2020 年 10 月 9 日
Could you specifically mention input types of vector?
If you would like to get length of array, below snap could be very small and beginer example:

skrowten_hermit
2020 年 10 月 9 日
採用された回答
その他の回答 (1 件)
Ameer Hamza
2020 年 10 月 9 日
編集済み: Ameer Hamza
2020 年 10 月 9 日
Yes, you can loop over an array using for loop
v1 = ; % signal 1
v2 = ; % signal 2
arrv = [v1, v2] % array of signal vectors
for i = arrv % arrv must be a row vector
i % takes values from arrv one at a time
end
1 件のコメント
That answer is not equivalent to the Python code shown in the question. In Python
arrv = [v1, v2]
creates a list with two elements, where arrv[0] == v1 and arrv[1] == v2.
In contrast this code in MATLAB
arrv = [v1, v2]
attempts to concatenate v1 and v2 horizontally, which if successful will result in one single array. The for operator then loops over the columns of that array, which if v1 and v2 are column vectors may give the same as Python, but if they are row vectors will give a very different result. I have never seen good code that relies on that strange for "feature".
カテゴリ
ヘルプ センター および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!