Linspace function in for loop
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Yen Tien Yap
 el 16 de Jul. de 2022
  
    
    
    
    
    Respondida: Star Strider
      
      
 el 16 de Jul. de 2022
            delta_l_2 = 1; % change in length of tendon 1 and tendon 2 (assume to be the same)
length_1_range = 10:-delta_l_2:5;
length_2_range = 20:delta_l_2:25;
[~,n] = size(length_1_range);
length_1 = zeros(100,n);
length_2 = zeros(100,n);
for i = 1:n 
    length_1(i) = linspace(0,length_1_range(i),100)'; % length of tendon 1
    for j = 1:n
        length_2(j) = linspace(0,length_2_range(j),100)'; % length of tendon 2
    end
end
I want to create arrays for length 1 and length 2 with values range from 0 to each value in length_1_range and length_2_range but it came out errrors when I run it. May I ask how to correct this code? Thank you!
0 comentarios
Respuesta aceptada
  Star Strider
      
      
 el 16 de Jul. de 2022
        Try this — 
delta_l_2 = 1; % change in length of tendon 1 and tendon 2 (assume to be the same)
length_1_range = 10:-delta_l_2:5;
length_2_range = 20:delta_l_2:25;
[~,n] = size(length_1_range);
length_1 = zeros(n,100);
length_2 = zeros(n,100);
for i = 1:n 
    length_1(i,:) = linspace(0,length_1_range(i),100)'; % length of tendon 1
    for j = 1:n
        length_2(j,:) = linspace(0,length_2_range(j),100)'; % length of tendon 2
    end
end
length_1
length_2
.
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

