Making each element of a row vector equal to zero
古いコメントを表示
Hi Everyone, I have a row vector (size 1*100) which contains randomly distributed 1s and 0s. How can i make each element of this row vector equal to zero using for loop ?
Sorry, if this is a very basic question !!
採用された回答
その他の回答 (2 件)
James Tursa
2014 年 5 月 27 日
編集済み: James Tursa
2014 年 5 月 27 日
You don't need a for loop. You can just do this:
row_vector(:) = 0; % Set all elements to 0, keep original variable type the same
2 件のコメント
Aftab Ahmed Khan
2014 年 5 月 27 日
James Tursa
2014 年 5 月 27 日
編集済み: James Tursa
2014 年 5 月 27 日
Not clear yet what you want. Are you trying to do this operation for only certain rows of a 2D matrix? If so, you can still do this without find and a for loop. E.g.,
BS_channeltable(1,:) = 0;
Is there some reason you need the indexes of these locations, other than to set their locations equal to 0?
George Papazafeiropoulos
2014 年 5 月 27 日
You can create a new vector with all zeros by typing the command:
new=zeros(1,100)
or by using a for loop:
for I=1:100
if v(I)==1
v(I)=0;
end
end
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!