How can i recover from this error, Sub scripted assignment dimension mismatch error?

I found it very difficult to recover from this error, please note that variable 'class(:,index)' has to accept 50 values, which method i should adapt, since its already having an index, i found it difficult to convert?
Subscripted assignment dimension mismatch.
Error in Test_Cross_Random (line 189)
[value class(:, index)] = min(tmp');
for trial = 1:total_trial
Dim = size(F_train,2) - round(size(F_train,2)*0.15); %0.15 0.20 0.25
disc_set = Eigenface_f(single(F_train),Dim);
F_train = disc_set'*F_train;
F_test = disc_set'*F_test;
for index = 1: length(para)
output{index} = classify(F_train, F_train_size, F_test, para(index));
tmp = output{index};
[value class(:, index)] = min(tmp');
[confusion, accur_CRT(trial), TPR, FPR] = confusion_matrix(class(:, index), F_test_size);
end
end

12 comentarios

What is tmp and what is class?
'class' is a builtin function by the way so you should not be naming variables this. If you didn't predeclare class as a variable then your line:
[value class(:, index)] = min(tmp');
will try to call the function class instead.
Stephen23
Stephen23 el 9 de En. de 2017
Editada: Stephen23 el 9 de En. de 2017
Do not use the variable name class. By naming your variable class you make the very important inbuilt function class impossible to use. For the same reason you should never use the variable names size, length, cell, i, j, etc. You can use which to check if a name is already used.
arun
arun el 9 de En. de 2017
Editada: arun el 9 de En. de 2017
temp contains a 117x8 matrix, the for loop runs for the first time to have a value accur_CRT = 64.5, it is showing this error in the 2nd time running of the loop.. but i want to take the average of accur_CRT.
Well, apart from anything else, if tmp is 117x8 why would you expect the min function to return 50 values?
arun
arun el 9 de En. de 2017
Editada: arun el 9 de En. de 2017
Actually i've to run 50 trials, i mean the accuracy should accept 50 values, but it manage to accept only one value. Changing the inbuild function class doesn't help, still having the same error. My program previously uses the word index, Please tell me whether index is an inbuild function or not.
Well, min( tmp' ) will give a vector 117 values for both outputs.
Maybe you just want
min( tmp(:) )
to get a single value each time?
The program is suggesting to preallocate the variable c(previously class). How to preallocate, can i declare like this c=[];
c = zeros( 1, 50 );
or whatever will pre-allocate. Pre-allocation is to give it a size normally. In the case of your previous name 'class' it would also turn it into a variable instead of the function, but generally you just want to tell it what size your variable is before you start trying to index into it for returning function results.
After applying what you said min(tmp(:)), i'm getting a different error
WRANING: wrong inputting!
Output argument "confusion" (and maybe others) not assigned during call to
"confusion_matrix
You need to preallocate to the final array size:
c = NaN(R,C)
for some R and C (you can figure them out yourself).
In my previous program without 50 trials, the value of c = 106x1, and value = 1x106
Thanks to all, who has helped me in this program

Iniciar sesión para comentar.

 Respuesta aceptada

There are two possible reasons for the error. We don't have enough information to know which is the cause of your problem:
1) the variable class already exists before the index loop and has different number of rows that the number of columns returned by min. To solve this, clear class before the loop or, better, preallocate it:
class = zeros(size(F_train, 1), numel(para));
for index = ...
output{index} = ...
[~, class(:, index)] = min(output{index}, [], 2); %This is much clearer than your double transpose
2) the numbers of rows in output{index} varies for each index. In which case, you can't assign the output of min to a matrix, as the number of elements will vary at each step. Store the output in a cell array:
class = cell(size(para));
for index = ...
output{index} = ...
[~, class{index}] = min(output{index}, [], 2); %This is much clearer than your double transpose

1 comentario

Thank u very much sir, i've cleared the value of class after the loop ends.. Now the program runs successfully...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 9 de En. de 2017

Comentada:

el 9 de En. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by