Clear Filters
Clear Filters

Unable to perform assignment because the left and right sides have a different number of elements.

1 view (last 30 days)
Hi all,
I am trying to divide a line as attached into 3 main increments which each has different thickness (size)
then divide the 3 increments into 3 sub increments
So I would like my the following results
t(i) =[5 10 20]
and my sub_t should be = [0 2.5 5 5 7.5 10 10 15 20 ]
clear all;
clc;
increments=[5 5 10]
t=0
for i=1:3
t(i)=t+increments(i)
%sub_t=linspace(t(i),t(i+1),3) could be
end

Accepted Answer

Chunru
Chunru on 29 Aug 2021
Edited: Chunru on 29 Aug 2021
increments=[5 5 10]
increments = 1×3
5 5 10
t0=0;
t = zeros(size(increments));
sub_t = [];
for i=1:3
%t(i)=t+increments(i)
t(i)=t0+increments(i);
sub_t=[ sub_t linspace(t0,t(i),3)];
t0 = t(i);
end
t
t = 1×3
5 10 20
sub_t
sub_t = 1×9
0 2.5000 5.0000 5.0000 7.5000 10.0000 10.0000 15.0000 20.0000
  4 Comments
sci hub
sci hub on 29 Aug 2021
Ok for t
but how could I have a vector of sub_t with all the 9 values ??
I tried to add a new loop with 9 but not working
i need my sub_t(i)=[0 2.5 .. 20 ]
Thanks again

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!