How can i recover from this error, Sub scripted assignment dimension mismatch error?
Afficher commentaires plus anciens
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 commentaires
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.
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.
Adam
le 9 Jan 2017
Well, apart from anything else, if tmp is 117x8 why would you expect the min function to return 50 values?
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?
arun
le 9 Jan 2017
Adam
le 9 Jan 2017
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.
arun
le 9 Jan 2017
You need to preallocate to the final array size:
c = NaN(R,C)
for some R and C (you can figure them out yourself).
arun
le 9 Jan 2017
arun
le 9 Jan 2017
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!