Linspace function in for loop
3 views (last 30 days)
Show older comments
Yen Tien Yap
on 16 Jul 2022
Answered: Star Strider
on 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 Comments
Accepted Answer
Star Strider
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Downloads in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!