Develop a Matlab function that remove all zeros  in an input vector(using while  loop)

1 次查看(过去 30 天)
using  while  loop

回答(1 个)

kowshik Thopalli
kowshik Thopalli 2017-11-27
编辑:kowshik Thopalli 2017-11-27
I agree with cvklpstunc that you dont need a while loop. If you are still looking for a while loop implementation, here is the code
count=1;z=1;
a=[1:10, zeros(5,1)'];
while count<=length(a)
if a(count)==0
zero_indices(z)=count;
z=z+1;
end
count=count+1;
end
a(zero_indices)=[];
Here is one line answer for what you want to do
b=a(find(a))
  2 个评论
James Tursa
James Tursa 2017-11-27
Please don't provide complete solutions to homework problems. Also your code has problems because it doesn't initialize zero_indices.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by