How do I get matlab to create a new cell array of varying length with every iteration of a for loop?

In this loop, FilterList is an existing cell array that contains words of a certain length, and wordLength is an input previously specified by the user.
NextGuess = 'e';
H = 1;
for j = 1:wordLength
for i = 1:length(FilterList)
if NextGuess == FilterList{i}(j)
NewList(H) = {FilterList{i}};
H = H+1;
end
end
end
I am trying to create a new cell array with every iteration, but instead it is grouping the results from all the iterations into NewList.

1 Comment

It would be helpful if you give some sample data and explain what's the purpose of your code. Maybe there is a better way to do it.

Sign in to comment.

 Accepted Answer

" a new cell array with every iteration,..."
Don't do that!!! Having the arrays as elements in the cell array instead or using a name structure, maybe is far better paradigm going forward. See the FAQ on why at How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop?

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 29 Apr 2015

Answered:

dpb
on 29 Apr 2015

Community Treasure Hunt

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

Start Hunting!