To merge matlab matrix horzcat

Asked 2 years ago, Updated 2 years ago, 71 views

There are 10 matrices from z to z10, as shown in the image.

Simply put,

zhorzcat = [z z2 z3 z4 z5 z6 z7 z8 z9 z10];

It's going to be 11x10.

What I'm curious about here is that assuming there are 100 matrices, it would be too much to write them one by one I wonder if there is another way.

matlab

2022-09-20 11:08

1 Answers

You can do it as below.

z1=ones(11,1);
z2=ones(11,1)*2;
z3=ones(11,1)*3;

z_sum=[];
for i=1:3
    eval("z_sum=[z_sum z"+num2str(i)+"];");
end


2022-09-20 11:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.