Creating loop with two variables
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello. I am trying to form a loop with two variables. Variable 1 which I call j = 1:12. Variable 2 which I call i = linspace(1,23,12). I am trying to create a cell named target{j} which has 12 different matrices of i:i+1. target{j} = i:i+1 , so that target{1} = 1:2, target{2} = 3:4, target{3} = 5:6, target{4} = 7:8, and so on.... Does anybody know how to do this? It would be great to get some help, thanks!
Risposte (1)
the cyclist
il 11 Ago 2021
You only really need one loop:
target = cell(size(j))
for j = 1:12
target{j} = [j j+1];
end
or zero loops:
j = num2cell(1:12);
target = cellfun(@(x)[x x+1],j,'UniformOutput',false)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!