Linspace function in for loop
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yen Tien Yap
le 16 Juil 2022
Réponse apportée : Star Strider
le 16 Juil 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 commentaires
Réponse acceptée
Star Strider
le 16 Juil 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 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!