How can I create new matrix with flexible size?

2 views (last 30 days)
Rebekka
Rebekka on 11 Aug 2014
Commented: dpb on 11 Aug 2014
I have the following code and I want to create tasksets T of flexible size e.g. via loop. How can this be done? I tried creation of t1 to t5 in for-loop, but then I fail in generating the matrix that is given taskset T:
>> t1=task('t1',2);
>> t2=task('t2',3);
>> t3=task('t3',1);
>> t4=task('t4',2);
>> t5=task('t5',4);
>> prec = [0 0 0 0 0;...
1 0 0 0 0;...
0 0 0 0 0;...
0 0 1 0 0;...
0 0 1 0 0];
>> T = taskset([t1 t2 t3 t4 t5],prec);
I am looking forward for your replys. Thank a lot, R.
  2 Comments
Patrik Ek
Patrik Ek on 11 Aug 2014
Edited: Patrik Ek on 11 Aug 2014
Flexible size matrices is not a good way to describe a problem. A matrix cannot be flexible since the memory allocation is done for a matrix with a well defined size. For example does A = [1,2,3;4,5,6;7,8,9]; allocate memory for a 3x3 double matrix and gives the element values from 1-9. Please describe what you mean by flexible size. Also what is task and to what toolbox does it belong? The reason that I ask is because I cannot find the function task on my computer or in the documentation on the web. However, if you have written the function yourself it is hard to say what is wrong unless you pass the full error message or show us the function.
dpb
dpb on 11 Aug 2014
Creating multiple variables of names like t1, t2, ..., t5 is in general a_bad_idea (tm) See the FAQ for why and alternatives in general.
It tends to lead at best to cluttered code like your statement
T = taskset([t1 t2 t3 t4 t5],prec);
where you've had to manually write each and every variable explicitly. This makes for very difficult to maintain and modify type of coding.
As the other responder says, w/o a definition for the functions task and taskset and some other background it's not feasible to offer concrete solutions, but this seems likely to be a non-optimal syntax/implementation leading to the question.

Sign in to comment.

Answers (0)

Categories

Find more on Shifting and Sorting Matrices 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!