# Problem with Vector Size

Hi, I'm supposed to write a program that goes through a matrix line by line and if it finds anything stores the column number of the 1 in a vector, if it finds nothing zero is supposed to be stored in that place. IF there's nothing in the entire row, an empty vector is to be stored that is 0 x 0 in length, that's the catch. I've written code that looks for anything on a line and stores it, but I can't get the code to store a 0 x 0 length empty vector for empty rows. I even go back through the code and set the relevant lines equal to [], but it doesn't give me a 0 x 0 vector, it yields a 1 x 0 vector. Can anyone help me to solve this?

function out = logipack(V)
m = size(V, 1);
S = cell(m, 1);
for r = 1:m
S{r} = find(V(r, );
m = size(V, 1);
if isempty(V(r))
S{r}= [];
end
end
out = S;
end

## Comments

• function out = logipack(V)
m = size(V, 1);
S = cell(m, 1);
for r = 1:m
S{r} = find(V(r, );
m = size(V, 1);
if isempty(V(r))
S{r}= [];
end
end
out = S;
end

• ``````function out = logipack(V)
m = size(V, 1);
S = cell(m, 1);
for r = 1:m
S{r} = find(V(r, :));
m = size(V, 1);
if isempty(V(r))
S{r}= [];
end
end
out = S;
end
``````
• The problem here is that the code produces a 1 x 0 empty vector if the line is all zeroes and not a 0 x 0 empty vector.

• ``````function out = logipack(V)
m = size(V, 1);
S = cell(m, 1);
for r = 1:m
S{r} = find(V(r, :));
end
for r = 1:m
for q = 1:m
if q==1
count=0;
end
if V(r,q)==0
count= count+1;
end
if count==m
S{r,1}=[];
end
end
end
out = S;
end
``````
• the last posted code works

Sign In or Register to comment.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!