Indexing a Matrix with a for loop

1 回表示 (過去 30 日間)
Emma
Emma 2019 年 10 月 17 日
回答済み: madhan ravi 2019 年 10 月 17 日
I have a matrix of complex numbers, z: z = [1+j 2+j 5+j;4+3j 6+2j 1+3j], and am trying to replicate z into y using a for loop. I thus have y = zeros(size(z));
My problem is that I do not know what to set i equal to in the for loop.
For example,
if I use
for i = size(z)
y(i) = z(i)
end,
i is only covering the output of the size. How can I make it such that i will include every matrix index?

採用された回答

madhan ravi
madhan ravi 2019 年 10 月 17 日
for ii = 1:numel(z) % don't name variables i or j (because they are interpreted as imaginary numbers by default)

その他の回答 (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