Storing value outside the loop using reshape function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Karanvir singh Sohal
el 12 de Abr. de 2021
Comentada: Karanvir singh Sohal
el 13 de Abr. de 2021
Hello everyone!
I was working on some code and I can't silly I'm doing. Here I have attached my problem in short format. I know its still quite lengthy but please help me out. After hours I'm unable to figure out what I'm doing wrong.
l=[4; 2.8];
[mL,nL]=size(l);
A=[15.0 22.5 30.0 37.5 45.0 52.5 60.0 ]';
for h=1:2
L=l(h);
X=[L*100/16 L*100/10];
XD = A(A>=X(1,1) & A<= X(1,2));
[mX,nX]=size(XD);
index = 0;
for i=1:mX
index=index+1;
LL(index)=l(h);
XDD(index)=XD(i);
end
A1 = [reshape(LL,[],1)];
A2 = [reshape(XDD,[],1)];
L=[A1 A2]
end
Running the above code gives following output:
L = 4 30
4 37.5
L = 2.8 22.5
4 37.5
Desired Output
L = 4 30
4 37.5
L = 2.8 22.5
0 comentarios
Respuesta aceptada
Stéphane Vaillant
el 12 de Abr. de 2021
t seems the variables LL and XDD are uninitialized and so keep their value on the second iteration of the loop. What happens when adding LL=[]; XDD=[]; just under "for h=1:2" ?
Más respuestas (0)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!