removing zeros from a stream of data

5 views (last 30 days)
stephen russell
stephen russell on 23 Mar 2014
Commented: stephen russell on 23 Mar 2014
i have figured out how to buffer randomly generated integers in to a vector with out actually making frames or using a buffer. the problem is i now have a stream of 187 zero vectors with a vector of 188 integers on the 188th instance. how do i remove the 187 zero vectors or how do i allow a MATLAB function block to with hold its output 187 times without getting the "Output argument 'y' is not assigned on some execution paths" error message?
thanks steve

Answers (1)

Image Analyst
Image Analyst on 23 Mar 2014
Hard to say without seeing your code but you can delete a variable with the clear() function. I don't know if your 188 vectors all have different names or if they are rows or columns in a 2D matrix. If they have different names:
clear('vector153'); % Delete the variable vector153.
If it's a 2D array and some columns are completely all 0's and you want to get rid of those, you can do
a = a(:,any(a));
  1 Comment
stephen russell
stephen russell on 23 Mar 2014
sorry. very simple program:
  • function [y,now] = vector_stack(x)
  • persistent array c;
  • now = 0;
  • if isempty(c) % initial declaration of variables
  • c = 1; % declaration of counter variable
  • array = zeros(188,1); % declaration of array variable
  • end;
  • array(c)= x;
  • if c == 188
  • now = 1;
  • c = 0;
  • end;
  • y = array;
  • c = c + 1;
i have a random integer block feeding into a "MATLAB function" block. when its like this it outputs a 187 zero vectors, 1 vector of 188 integers, and repeats. i want to do away with the zeros. or if i have the program like this:
  • function [y,now] = vector_stack(x)
  • persistent array c;
  • now = 0;
  • if isempty(c) % initial declaration of variables
  • c = 1; % declaration of counter variable
  • array = zeros(188,1); % declaration of array variable
  • end;
  • array(c)= x;
  • if c == 188
  • now = 1;
  • c = 0;
  • y = array;
  • end;
  • c = c + 1;
i get the "Output argument 'y' is not assigned on some execution paths" error. yes i know it doesn't output 187 times thats what the error is saying. i want it to function this way. how do i get it to function this way correctly. i am trying to do what a buffer does without using a buffer.
thanks steve

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!