MATLAB Answers

For loop assignment error

2 views (last 30 days)
Hi all,
I have crated a set of equations assigned to a letter and contains a variable that goes until 14002, to fill a matrix with this computations I am trying the following:
Axz = zeros(14002,4);
for i=1:14002
Axz(:,i) = [dxx,dxx_,dxz,dxz_;dzx,dzx_,dzz,dzz_];
The problem comes with the followinf Error:
Unable to perform assignment because the size of the left side is 14002-by-1 and the size of the right side is 14002-by-4.
Error in Test (line 51)
Axz(:,i) = [dxx,dxx_,dxz,dxz_;dzx,dzx_,dzz,dzz_];
How can I set the left side to be 14002 by 4?
Thanks for you help!

Answers (1)

VBBV on 16 May 2021
Edited: VBBV on 16 May 2021
%f true
%f true
Axz = zeros(14002,4);
for i=1:2:length(Axz)-1
Axz(i:i+1,:) = [dxx,dxx_,dxz,dxz_;dzx,dzx_,dzz,dzz]
Hugo Hernández Hernández
@VBBV sorry for my unclearness in my statement, although I have mentioned it's not really clear, each dxx,dxx_,dxz... element contains 7001 different values because they are in function of a variable t that goes from 0 to 7000 so I guess that is messing with my solutions using the structures you provided.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!