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

조회 수: 1 (최근 30일)
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
arun
arun 2017년 1월 9일
In my previous program without 50 trials, the value of c = 106x1, and value = 1x106
arun
arun 2017년 1월 9일
Thanks to all, who has helped me in this program

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2017년 1월 9일
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
arun
arun 2017년 1월 9일
Thank u very much sir, i've cleared the value of class after the loop ends.. Now the program runs successfully...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by