0
votes

I have a table from which I extract the largest element in each column defendant and his place in the table.

Max = max(ARRAY,[],1); for i=1:1 for j=1:30 [X,Y] = find(ARRAY == Max(i,j)); Locations(i,j)=X; end end

I want to get a table Sample_Targets (i, j) 10 * 30 where depending on the value of (Locations (i, j)) from (1-10) to store in each column is a variable of type A = [1;0;0;0;0; 0;0;0;0;0];

  for i=1:1 
for j=1:30
    switch  Locations(i,j)
            case {1}
                Sample_Targets(i,j) = [1;0;0;0;0;0;0;0;0;0];
            case {2}
                Sample_Targets(i,j) = [0;1;0;0;0;0;0;0;0;0];
            case {3}
                Sample_Targets(i,j)  = [0;0;1;0;0;0;0;0;0;0];
            case {4}
                Sample_Targets(i,j)  = [0;0;0;1;0;0;0;0;0;0];
            case {5}
                Sample_Targets(i,j)  = [0;0;0;0;1;0;0;0;0;0];
            case {6}
                Sample_Targets(i,j)  = [0;0;0;0;0;1;0;0;0;0];
            case {7}
                Sample_Targets(i,j)  = [0;0;0;0;0;0;1;0;0;0];
            case {8}
                Sample_Targets(i,j)  = [0;0;0;0;0;0;0;1;0;0];
            case {9}
                Sample_Targets(i,j)  = [0;0;0;0;0;0;0;0;1;0];
            case {10}
                Sample_Targets(i,j)  = [0;0;0;0;0;0;0;0;0;1];
         end    
    end
  end

Every time I get the same error:

Subscripted assignment dimension mismatch.

What can I do?

1
Please provide code which allows to reproduce your problem, including initialisation of all variables. - Daniel
This is all my friend. - Lateras

1 Answers

0
votes

Either your Sample_Targets variable needs to be of the cell type, or, alternatively, a 3D array.

  • Cell: Use {} for cell subscripts, i.e. Sample_Targets{i,j}

  • 3D array: Use Sample_Targets(i,j,:) = [ .... ];

Note, the latter is only possible because in your switch statement you always assign an array with the same size. If that would not be the case, option a) is the only possible.