Linspace function in for loop
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yen Tien Yap
am 16 Jul. 2022
Beantwortet: Star Strider
am 16 Jul. 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 Kommentare
Akzeptierte Antwort
Star Strider
am 16 Jul. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!