arrays in loops, changing variable names (i.e. A{1}, A{2}, ...)

I'm trying to use arrays to store information in a different variable with each iteration in a for-loop.
I used A{i}=edge(BW,'canny'); inside the loop (using curly brackets as the information is a matrix)
However, once I run the program, matlab does not return a A{1} or A{2} (and so on), but A{i} does exist. Any advice on what I've done wrong?

 Accepted Answer

I don't see any problem in your code, look at this example
for k=1:3
BW=rand(50);
s{k} = edge(BW,'canny');
end
celldisp(s)

2 Comments

please see my comment underneath the question. My program does not return values for A{1} or any other value of i
If your matrices have different sizes, it is not a problem
for k=1:3
N=10+k
BW=rand(N);
s{k} = edge(BW,'canny');
end
s{1}
s{2}
To make your question clear, please post your code

Sign in to comment.

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!