How to edit a 3D matrix least square problem with for circulation;N-dimensional indexing allowed for Full matrices only

I want to solve a matrix least square problem, the solution is a 44 matrix. A 44matrix multiply a 41 matrix obtain a 41 matrix. If I repeat the process, it can be represented as a 44matrix multiply a 4N matrix obtain a 4*N matrix, I want to solve the problem in Matlab using for circulation, but the wrong code(N-dimensional indexing allowed for Full matrices only) appeared after running the program.
first form:
for i=1:3
cvx_begin
variable muler(4,4);
minimize(norm(muler(4,4)*xx-double(sp3(:,:,i))));
cvx_end
mu(:,:,i)=muler(4,4);
end

second form:
for i=1:3
sp4=double(sp3(:,:,i));
cvx_begin
variable muler(4,4);
minimize(norm(muler(4,4)*xx-sp4));
cvx_end
mu(:,:,i)=muler(4,4);
end
Both of the code is wrong, how to solve the problem? I use i=3 for simple calculation.

Show us the output of ’whos' from just before the minimize statement, so that we know what the dimensions are everything are. Here is a hint: if instead of declaring mule as a CVX variable, you just make up a numerical matrix of the same dimensions, such as eye(4), the expression inside the minimize() better be conformal, i.e., should evaluate in MAT:AB without producing an error message. Get that correct first. Then go back to declaring mule as a CVX variable.

is it your intention that the expression being minimized is a vector? If so, then norm is what you likely want. However, if the result is supposed to be a (non-vector) matrix, then perhaps you want norm(…,‘fro’)/.

Thank you!

This is a right code:

sp5=[28788,36006,42048,46365,48284,48175;
3768,5761,10542,16867,24186,31492;
28353,21313,13689,8001,4134,3749;
47564,46624,43351,38710,32395,24765];

xx=[49790,49790,49790,49790,49790,49790;
49790,46787.2955889304,38141.3528228939,24895.0000000000,8645.94276603647,-8645.94276603646;
0,17029.1829361850,32004.3950862928,43119.4048544272,49033.5780224778,49033.5780224778;
0,0,0,0,0,0];
cvx_begin
variable muler(4,4);
minimize(norm(muler*xx-sp5));
cvx_end

The out put is named as muler, it is a 44 matrix, when we have many other sp5, then sp5 changed to a 46N matrix, xx remains the same, a 46 matrix, the output should be N number of 4*4 matrix. I want to realize the process by a circulation rather than calculate the muler one by one, then there is a problem that I can’t realize it.
I want to use only three sp5 to calibrate the code.
The other two sp5 are:
sp5=[29131 36241 42214 46221 47758 48472;
3770 5608 10524 16486 24328 31739;
28194 20933 13914 7758 4132 3847;
46757 46275 43207 38334 32333 24727];

sp5=[28774 36492 42283 45925 47956 47889;
3727 5551 10458 16821 24298 31181;
28234 20971 13511 7949 4094 3786;
46605 45726 42739 38324 31713 24225 ];

It sounds like you have N separate optimization problems to run. So use a for loop;

% sp is 4 by 6 by N array
for i=1:N
  cvx_begin
  variable muler(4,4);
  minimize(norm(muler*xx-sp(:,:,i));
  cvx_end
 % Save the results or do whatever you want
end  :

Thank you very much!
It works, but I don’t know why the first form of code in my original question can’t work, it looks like the same as yours.
Anyway, I am glad it works.
Best wishes!
Thank you!

Your first post has muler(4,4)*xx where it should be muler*xx .
muler(4,4) is just a single element of the matrix, muler, not the entire matrix.

You also presumably want
mu(:,:,i)=muler;
rather than
mu(:,:,i)=muler(4,4);

Thank you
I’m just beginning to learn to use the CVX tools and I am reading “The CVX Users’ Guide” edited by Michael C. Grant, Stephen P. Boyd, it is useful. I made a mistake that led directly to the code can’t work. In Chinese it would be 差之毫厘谬以千里.
I will study hard and make progress!