MATLAB: In an assignment A(I) = B, the number of elements in B and I must be the same

for looplinspaceloop

Hello everyone! I'm having some issues trying to solve my code:
psi=[45*pi/180 50*pi/180 35*pi/180 40*pi/180];
for j=1:3;
psii(j)=linspace(psi(j),psi(j+1),50);
end
I have lots of linearly spaced vectors. I need to creat loop to make easier my work. I got error as: In an assignment A(I) = B, the number of elements in B and I must be the same. I know it is an easy question but I am a new user. I tried to find solution by looking for similar questions. I didnt solved it unfortunately. Could you please help me?
If I use following codes I can solve it, but I need to create loop. psi1=linspace(psi(1),psi(2),50);
psi2=linspace(psi(2),psi(3),50);
psi3=linspace(psi(3),psi(4),50);
Thanks in advance.

Best Answer

Allow for a second dimension.
This works:
psii(j,:)=linspace(psi(j),psi(j+1),50);
It will give you a (3x50) matrix.
I also congratulate you for wanting to go with the matrix rather than with dynamic variables!
Related Question