How can I create a function of my code
Afficher commentaires plus anciens
Hi, I got a code that I want to convert to a a function so I do not write for each variable the whole code. I do not really understand the documentation page because I have a code that is quite big and I get confused. My code is to generate the same variable without the doubles inside. The output that I want is the same name as the variable input. So that is where I got the problem. I post the code so you can see:
function y = removedbl(var)
numCells = numel(Time_msg_match); %Time_msg_match was the original variable for this code was created
Time_msg_match2 = zeros(numCells+10000, 1);
vector2Index = 1;
for k = 1 : numCells
len = length(Time_msg_match{k});
if len == 1
Time_msg_match2(vector2Index) = Time_msg_match{k};
vector2Index = vector2Index + 1;
else
fprintf('Row %d has %d elements in it.\n', k, length(Time_msg_match{k}));
for k2 = 1 : len
thisVector = Time_msg_match{k};
Time_msg_match2(vector2Index) = thisVector(k2);
vector2Index = vector2Index + 1;
end
end
end
if vector2Index < numCells
Time_msg_match2 = Time_msg_match2(1 : vector2Index - 1);
end
% fprintf('Original Time_msg_match had %d rows.\n', numCells) %Nos dice de que numero a que numero pasamos al quitar las celdas vacias
% fprintf('Afterwards Time_msg_match had %d rows.\n', numel(Time_msg_match2))
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!