1

I have a 42 variables of same length and in sequence

e.g. d_reshaped1 to d_reshaped42.

Each variable has 3 rows with 42 elements. I would like to combine all the first rows in each of the 42 variables to a single 42 by 42 matrix but my dynamic programming skills in Matlab are miserable.

Can someone assist?

2
  • Please consider seriously to define a cell array of size 42, or better yet a 3D array of size 3x42x42 to accomodate all your variables. That will make life easier :-) Commented Jan 3, 2014 at 20:17
  • It will but my question is how do i assign the variables into the 3D cell array in a loop? Commented Jan 3, 2014 at 20:23

1 Answer 1

1

If you really have those variables, you need to use eval, which is generally not advised:

result = NaN(42,42);
for k = 1:42
    eval(['result(k,:) = d_reshape' num2str(k) '(1,:)'])
end

You should consider using a higher-order structure to store all those variables together, such as a cell array or a 3D array.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much. Not recommended but I really need to get past this problem ASAP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.