How to make a loop to simplify the code?
Mostra commenti meno recenti
Hello, I would like to know if there is any way to do this but in a general way, such as with a cycle, it could be an if or a while, but I am not very clear about how it would be, could someone help me?
First what I do is define the variables as an empty vector:
p=1;
q=2;
ps1=[];
ps2=[];
ps3=[];
ps4=[];
ps5=[];
ps6=[];
ps7=[];
ps8=[];
ps9=[];
ps10=[];
numpuntos=length(Lk)/2;
%%%%%%this is where I would like to create the loop to simplify the code%%%%%
ps1=[ps1,InterX(L1,Lk([1: 2],[p: q])),InterX(L2,Lk([1: 2],[p: q])),InterX(L3,Lk([1: 2],[p: q])),InterX(L4,Lk([1: 2],[p: q])),InterX(L5,Lk([1: 2],[p: q])),InterX(L6,Lk([1: 2],[p: q])),InterX(L7,Lk([1: 2],[p: q])),InterX(L8,Lk([1: 2],[p: q])),InterX(L9,Lk([1: 2],[p: q])),InterX(L10,Lk([1: 2],[p: q])),InterX(L11,Lk([1: 2],[p: q]))];
ps2=[ps2,InterX(L1,Lk([1: 2],[p+2: q+2])),InterX(L2,Lk([1: 2],[p+2: q+2])),InterX(L3,Lk([1: 2],[p+2: q+2])),InterX(L4,Lk([1: 2],[p+2: q+2])),InterX(L5,Lk([1: 2],[p+2: q+2])),InterX(L6,Lk([1: 2],[p+2: q+2])),InterX(L7,Lk([1: 2],[p+2: q+2])),InterX(L8,Lk([1: 2],[p+2: q+2])),InterX(L9,Lk([1: 2],[p+2: q+2])),InterX(L10,Lk([1: 2],[p+2: q+2])),InterX(L11,Lk([1: 2],[p+2: q+2])),InterX(L12,Lk([1: 2],[p+2: q+2]))];
ps3=[ps3,InterX(L1,Lk([1: 2],[p+4: q+4])),InterX(L2,Lk([1: 2],[p+4: q+4])),InterX(L3,Lk([1: 2],[p+4: q+4])),InterX(L4,Lk([1: 2],[p+4: q+4])),InterX(L5,Lk([1: 2],[p+4: q+4])),InterX(L6,Lk([1: 2],[p+4: q+4])),InterX(L7,Lk([1: 2],[p+4: q+4])),InterX(L8,Lk([1: 2],[p+4: q+4])),InterX(L9,Lk([1: 2],[p+4: q+4])),InterX(L10,Lk([1: 2],[p+4: q+4])),InterX(L11,Lk([1: 2],[p+4: q+4])),InterX(L12,Lk([1: 2],[p+4: q+4]))];
ps4=[ps4,InterX(L1,Lk([1: 2],[p+6: q+6])),InterX(L2,Lk([1: 2],[p+6: q+6])),InterX(L3,Lk([1: 2],[p+6: q+6])),InterX(L4,Lk([1: 2],[p+6: q+6])),InterX(L5,Lk([1: 2],[p+6: q+6])),InterX(L6,Lk([1: 2],[p+6: q+6])),InterX(L7,Lk([1: 2],[p+6: q+6])),InterX(L8,Lk([1: 2],[p+6: q+6])),InterX(L9,Lk([1: 2],[p+6: q+6])),InterX(L10,Lk([1: 2],[p+6: q+6])),InterX(L11,Lk([1: 2],[p+6: q+6])),InterX(L12,Lk([1: 2],[p+6: q+6]))];
ps5=[ps5,InterX(L1,Lk([1: 2],[p+8: q+8])),InterX(L2,Lk([1: 2],[p+8: q+8])),InterX(L3,Lk([1: 2],[p+8: q+8])),InterX(L4,Lk([1: 2],[p+8: q+8])),InterX(L5,Lk([1: 2],[p+8: q+8])),InterX(L6,Lk([1: 2],[p+8: q+8])),InterX(L7,Lk([1: 2],[p+8: q+8])),InterX(L8,Lk([1: 2],[p+8: q+8])),InterX(L9,Lk([1: 2],[p+8: q+8])),InterX(L10,Lk([1: 2],[p+8: q+8])),InterX(L11,Lk([1: 2],[p+8: q+8])),InterX(L12,Lk([1: 2],[p+8: q+8]))];
ps6=[ps6,InterX(L1,Lk([1: 2],[p+10: q+10])),InterX(L2,Lk([1: 2],[p+10: q+10])),InterX(L3,Lk([1: 2],[p+10: q+10])),InterX(L4,Lk([1: 2],[p+10: q+10])),InterX(L5,Lk([1: 2],[p+10: q+10])),InterX(L6,Lk([1: 2],[p+10: q+10])),InterX(L7,Lk([1: 2],[p+10: q+10])),InterX(L8,Lk([1: 2],[p+10: q+10])),InterX(L9,Lk([1: 2],[p+10: q+10])),InterX(L10,Lk([1: 2],[p+10: q+10])),InterX(L11,Lk([1: 2],[p+10: q+10])),InterX(L12,Lk([1: 2],[p+10: q+10]))];
ps7=[ps7,InterX(L1,Lk([1: 2],[p+12: q+12])),InterX(L2,Lk([1: 2],[p+12: q+12])),InterX(L3,Lk([1: 2],[p+12: q+12])),InterX(L4,Lk([1: 2],[p+12: q+12])),InterX(L5,Lk([1: 2],[p+12: q+12])),InterX(L6,Lk([1: 2],[p+12: q+12])),InterX(L7,Lk([1: 2],[p+12: q+12])),InterX(L8,Lk([1: 2],[p+12: q+12])),InterX(L9,Lk([1: 2],[p+12: q+12])),InterX(L10,Lk([1: 2],[p+12: q+12])),InterX(L11,Lk([1: 2],[p+12: q+12])),InterX(L12,Lk([1: 2],[p+12: q+12]))];
ps8=[ps8,InterX(L1,Lk([1: 2],[p+14: q+14])),InterX(L2,Lk([1: 2],[p+14: q+14])),InterX(L3,Lk([1: 2],[p+14: q+14])),InterX(L4,Lk([1: 2],[p+14: q+14])),InterX(L5,Lk([1: 2],[p+14: q+14])),InterX(L6,Lk([1: 2],[p+14: q+14])),InterX(L7,Lk([1: 2],[p+14: q+14])),InterX(L8,Lk([1: 2],[p+14: q+14])),InterX(L9,Lk([1: 2],[p+14: q+14])),InterX(L10,Lk([1: 2],[p+14: q+14])),InterX(L11,Lk([1: 2],[p+14: q+14])),InterX(L12,Lk([1: 2],[p+14: q+14]))];
ps9=[ps9,InterX(L1,Lk([1: 2],[p+16: q+16])),InterX(L2,Lk([1: 2],[p+16: q+16])),InterX(L3,Lk([1: 2],[p+16: q+16])),InterX(L4,Lk([1: 2],[p+16: q+16])),InterX(L5,Lk([1: 2],[p+16: q+16])),InterX(L6,Lk([1: 2],[p+16: q+16])),InterX(L7,Lk([1: 2],[p+16: q+16])),InterX(L8,Lk([1: 2],[p+16: q+16])),InterX(L9,Lk([1: 2],[p+16: q+16])),InterX(L10,Lk([1: 2],[p+16: q+16])),InterX(L11,Lk([1: 2],[p+16: q+16])),InterX(L12,Lk([1: 2],[p+16: q+16]))];
ps10=[ps10,InterX(L1,Lk([1: 2],[p+18: q+18])),InterX(L2,Lk([1: 2],[p+18: q+18])),InterX(L3,Lk([1: 2],[p+18: q+18])),InterX(L4,Lk([1: 2],[p+18: q+18])),InterX(L5,Lk([1: 2],[p+18: q+18])),InterX(L6,Lk([1: 2],[p+18: q+18])),InterX(L7,Lk([1: 2],[p+18: q+18])),InterX(L8,Lk([1: 2],[p+18: q+18])),InterX(L9,Lk([1: 2],[p+18: q+18])),InterX(L10,Lk([1: 2],[p+18: q+18])),InterX(L11,Lk([1: 2],[p+18: q+18])),InterX(L12,Lk([1: 2],[p+18: q+18]))];
paredes1=length(ps1);
paredes2=length(ps2);
paredes3=length(ps3);
paredes4=length(ps4);
paredes5=length(ps5);
paredes6=length(ps6);
paredes7=length(ps7);
paredes8=length(ps8);
paredes9=length(ps9);
paredes10=length(ps10);
vectorparedes=[];
vectorparedes=[vectorparedes,length(ps1),length(ps2),length(ps3),length(ps4),length(ps5),length(ps6),length(ps7),length(ps8),length(ps9),length(ps10)];
If someone could help me I would be very grateful, thanks.
3 Commenti
David Hill
il 20 Giu 2022
What are L1, L2, ....,L12, Lk, p, q ? attach files or provide examples.
dpb
il 20 Giu 2022
What are you trying to do in words instead of tyring to read uncommented code that is fairly strange to look out without a fair study.
What is InterX?
Risposte (0)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!