Getting the if or while loop to work
Mostrar comentarios más antiguos
Hi i like to ask for some help please
n=20;
iter_h=0;
x=rand(n,1);
for i=1:n-1
h(i,:)=x(i+1)-x(i)
iter_h=iter_h+1
while i ==4
SLPS=[1 0 0 0;0 h(1) 2*(h(2)+h(1)) h(2);0 0 h(2) 2*(h(3)+h(2));0 0 0 h(3)]
end
% if i==19
% SLPS=rand(i,1)
% end
% if n==4
% SPLS_4=[1 0 0 0;0 h(1) 2*(h(2)+h(1) h(2);0 0 h(2) 2*(h(3)+h(2));0 0 0 h(3)]
end
when i use the while loop, the code cannot stop running however if i use the if, it does not show my SLPS matrix as shown, in fact it does not show anything.
My Question and main goals is to create a matrix when the i=4 or n=4 and when i=20, another matrix assuming the matrix using the random but i have another set of function to run.
How can i do so to overcome this problem, as it is very important for me to know how to get the matrix for those two case, other i values are not important if cannot be found a code which can produce as such. Most important points are when i=4 and i=20.
1 comentario
Jan
el 19 de Mzo. de 2021
Please use the tools above the edit field to format the code. This improves the readability.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!