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
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
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.
the last posted code works